您好,我想打开一个 csv 文件并在其中写入文本。这是代码:
尝试
Dim path As String = "C:\Users\daaemoon\Desktop\Test.csv"
Dim reader As StreamReader = New System.IO.StreamReader(File.OpenRead(path))
Dim sw As New StreamWriter(path)
Dim s As String = String.Empty
While reader.Peek() >= 0
Dim line As String = reader.ReadLine()
Dim values As String() = line.Split(";"c)
listforfalsecsv.Add(values(0))
s = s + line + Chr(10)
End While
reader.Close()
sw.Write(s)
sw.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
我通过以下行得到了错误:
Dim sw As New StreamWriter(path)
如果我在该行之后使用方法 reader.dispose() Dim reader As StreamReader = New System.IO.StreamReader(File.OpenRead(path))
我来到了while循环,但我得到了一个错误:无法读取来自关闭的文本阅读器。
我需要帮助,请帮助我。