سؤال

 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