vb.net stramreader 讀文字檔
Imports System.IO
Public Class _03_StreamReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim theFile As FileStream = File.Open("d:\temp\asdf.txt", FileMode.Open, FileAccess.Read)
Dim rdr As StreamReader = New StreamReader(theFile)
TextBox1.Text = rdr.ReadToEnd()
rdr.Close()
theFile.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rdr As StreamReader = File.OpenText("d:\temp\asdf.txt")
TextBox1.Text = rdr.ReadToEnd()
rdr.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MsgBox(File.ReadAllText("d:\temp\asdf.txt"))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim rdr As StreamReader = File.OpenText("d:\temp\asdf.txt")
While Not rdr.EndOfStream
Dim ft As String = rdr.ReadLine()
If ft.Contains(TextBox2.Text) Then
MsgBox("Found " & TextBox2.Text & vbNewLine & ft)
End If
End While
End Sub
End Class
0 意見:
張貼留言