質問

 Dim file_lines() As String = System.IO.File.ReadAllLines("c:/file.txt")  
                lone_lines(1) = final_lone  
                'lone_lines(here is the line number) = final_lone   
                System.IO.File.WriteAllLines(Add, lone_lines)  

It does its work. But I Want to access the same file again later. I want to Close the file writer which remains open.

Any ideas?

Thank you.

役に立ちましたか?

解決

Use FileStream and StreamReader to avoid locks on files

    Dim fs As New FileStream("c:\file.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
    Dim oRead As New System.IO.StreamReader(fs)
    Dim file_lines As String = oRead.ReadToEnd
    oRead.Close()
    System.IO.File.WriteAllText("C:\file2.txt", file_lines)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top