-1
 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.

  • What is the parameter lone_lines? What is the parameter final_lone? what is the Parameter Add? Since I don't know which file you are writing to I am unable to help you. – WozzeC Apr 09 '14 at 06:56
  • What makes you think that it remains open? – Matt Wilko Apr 09 '14 at 08:05

1 Answers1

0

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)
ɐsɹǝʌ ǝɔıʌ
  • 4,440
  • 3
  • 35
  • 56