How to check if the text file is open and close the text file?

后端 未结 5 1087
忘了有多久
忘了有多久 2020-12-06 15:38

I am trying to save the text file in this path:\"C:\\Test\\test.txt\" and when the file is already opened I need to check whether the file is opened and I need to close it b

5条回答
  •  春和景丽
    2020-12-06 16:16

    What about :

    If File.Exists("File1.txt") = False Then
                File.CreateText("File1.txt").Close()
            Else
                Exit Sub
            End If
    
            If File.Exists("File2.txt") = False Then
                File.CreateText("File2.txt").Close()
            Else
                Exit Sub
            End If
    End If
    

提交回复
热议问题