在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中实现文件读写操作的两种常见方法,根据具体需求选择适合的方法来进行操作。