|
Error whe reading a file -- antenn --
I try to read a file text using this code: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fileReader As System.IO.StreamReader fileReader = _ My.Computer.FileSystem.OpenTextFileReader("C:\\hpfr3740.log") Dim stringReader As String stringReader = fileReader.ReadLine() Do While Not stringReader Is Nothing RichTextBox1.AppendText(stringReader) stringReader = fileReader.ReadLine() Loop End Sub End Class Above code is working, below code is working too Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myText As String Dim objStreamReader As System.IO.StreamReader objStreamReader = New System.IO.StreamReader("C:\\hpfr3740.log") myText = objStreamReader.ReadLine Do While Not myText Is Nothing RichTextBox1.AppendText(myText) myText = objStreamReader.ReadLine Loop End Sub End Class Which one better? |
|
Read Text from a File with Visual Basic .NET -- helmet2 --
I think both codes is fine. Its depend on your file. If you read text file, its better use first codes. If your file is not text, its better to use the second codes. |
|
Read TXT File -- antenn --
Hmm.. thank you for your advice. Acctually i want to read a txt file. |