在VB中,可以使用以下方法實現文件的讀寫操作:
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\test.txt")
Dim line As String
line = fileReader.ReadLine()
While Not line Is Nothing
Console.WriteLine(line)
line = fileReader.ReadLine()
End While
fileReader.Close()
Dim fileWriter As System.IO.StreamWriter
fileWriter = My.Computer.FileSystem.OpenTextFileWriter("C:\test.txt", True)
fileWriter.WriteLine("Hello, World!")
fileWriter.Close()
Dim contents As String
contents = System.IO.File.ReadAllText("C:\test.txt")
Console.WriteLine(contents)
Dim text As String = "Hello, World!"
System.IO.File.WriteAllText("C:\test.txt", text)
以上是在VB中實現文件讀寫操作的兩種常見方法,根據具體需求選擇適合的方法來進行操作。