Vb.net进程无法访问该文件,因为它正由另一个进程

时间:2015-09-23 11:10:37

标签: vb.net stream reader

您好我想打开一个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)

如果我在该行Dim reader As StreamReader = New System.IO.StreamReader(File.OpenRead(path))

之后使用方法reader.dispose()

我来到了while循环,但是我得到了一个错误:来自一个克隆的Textreader无法读取。

我需要帮助,请帮助我。

0 个答案:

没有答案