① 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()