vb.net读写文本文件简单示例
写
Dim strFilePath As String =SaveFileDialog1.FileName
Dim sw As StreamWriter = New StreamWriter(strFilePath, True) 'true是指以追加的方式打开指定文件
For i = 0 To j
temp = i.ToString
sw.WriteLine(temp)
sw.Flush()
Next
sw.Close()
sw = Nothing
Dim sw As StreamWriter = New StreamWriter(strFilePath, True) 'true是指以追加的方式打开指定文件
For i = 0 To j
temp = i.ToString
sw.WriteLine(temp)
sw.Flush()
Next
sw.Close()
sw = Nothing
读
Dim line As String
Dim sr As StreamReader = New StreamReader(strPath, System.Text.Encoding.Default)
Do While sr.Peek() > 0
line = sr.ReadLine()
Loop
sr.Close()
sr = Nothing '构造函数new
Public Sub New(Path, Encoding)
Dim sr As StreamReader = New StreamReader(strPath, System.Text.Encoding.Default)
Do While sr.Peek() > 0
line = sr.ReadLine()
Loop
sr.Close()
sr = Nothing '构造函数new
Public Sub New(Path, Encoding)