① VB如何将程序的数据保存
写入:
Open "D:123.txt" For Output As #1 '打开XXX路径的XXX文件(双引号里表示文件位置和文件名)
Print #1, Text1.Text '写入Text1的Text内容
Close #1 '关闭
读取:
Open "D:123.txt" For Input As #1 '打开打开XXX路径的XXX文件(双引号里表示文件位置和文件名)
Do While Not EOF(1)
Line Input #1, s
Text1.Text = s
Loop 'Do...Loop表示循环读取文件的内容,并让Text1.Text=内容
Close #1 '关闭
① 使用File.ReadAllText 读取
Dim s As String = System.IO.File.ReadAllText("C:a.txt")
② 使用 StreamReader 读取,注意编码格式和写入的编码保持一致。
Dim sr As StreamReader = New StreamReader("C:a.txt", System.Text.Encoding.UTF8)
Dim s As String = sr.ReadToEnd()
sr.Close()