How to solve this . The process cannot access the file

前端 未结 2 987
渐次进展
渐次进展 2021-01-22 07:05

The process cannot access the file \'F:\\copy back up\\system\\HRM 2-5-2013\\HRM\\HRM\\lanbased.txt\' because it is being used by another process. This is my code in sub main

相关标签:
2条回答
  • 2021-01-22 07:40

    Looks like you need to close your streamReader before opening the new form:

    objReader.Close()
    

    That will free the file.

    0 讨论(0)
  • 2021-01-22 07:51

    first you open your file for reading here :

    Dim objReader As New System.IO.StreamReader(NAME1)    //1st open
    

    Second you call the form1 : Application.Run(New Form1())

    in that Form you have : Dim objWriter As New System.IO.StreamWriter(FILE_NAME) //2nd open

    But wait you didn't close your file so you can't open it 2nd time for writing.

    So you need to close the file before calling create form 1 like objReader.close()

            conn.Open()
            objReader.close()    <----- this one
            Application.Run(New Form1())
    
    0 讨论(0)
提交回复
热议问题