我有这个代码。
Dim txtVern As String = String.Empty
Try
Using verSR As New StreamReader(appDataVersionLoc)
txtVern = verSR.ReadToEnd()
End Using
Catch ex As Exception
Dim verFile As System.IO.FileStream
verFile = System.IO.File.Create(appDataVersionLoc)
Dim wWFERes As DialogResult = MessageBox.Show("Version file missing/corrupt, created a new one.")
If My.Computer.FileSystem.FileExists(appDataVersionLoc) Then
My.Computer.FileSystem.WriteAllText(appDataVersionLoc, "0.0.0.0", True)
End If
End Try
但是当它试图执行时My.Computer.FileSystem.WriteAllText(appDataVersionLoc, "0.0.0.0", True)
,我得到了这个错误:
该进程无法访问文件“C:\Users\Dubstaphone\AppData\Roaming\TheArena\version.txt”,因为它正被另一个进程使用。
我该如何避免这种情况?我所做的是让它创建一个名为“version.txt”的文本文件,如果它不存在的话。现在我试图给它写“0.0.0.0”,但它给了我这个错误。顺便说一句,“appDataVersionLoc”等于GetFolderPath(SpecialFolder.ApplicationData) & "\TheArena\version.txt"
这个变量适用于其他一切。
谢谢!
附言
我是个十足的菜鸟。