The process cannot access the file because it is being used by another process,该怎么解决
The process cannot access the file because it is being used by another process
我使用My.Computer.FileSystem.WriteAllText和My.Computer.FileSystem.ReadAllText方式读写txt文件,但是时不时会出现The process cannot access the file because it is being used by another process的问题,有谁知道是怎么回事么?
是不是使用My.Computer.FileSystem.WriteAllText和My.Computer.FileSystem.ReadAllText方式读写文件会打开文件一段时间,而不是随着该语句结束马上关闭?

------解决思路----------------------
以下 Reflector 代码,证明文件读写完就关闭的。
你的杀毒软件关闭了没有?
我使用My.Computer.FileSystem.WriteAllText和My.Computer.FileSystem.ReadAllText方式读写txt文件,但是时不时会出现The process cannot access the file because it is being used by another process的问题,有谁知道是怎么回事么?
是不是使用My.Computer.FileSystem.WriteAllText和My.Computer.FileSystem.ReadAllText方式读写文件会打开文件一段时间,而不是随着该语句结束马上关闭?
------解决思路----------------------
以下 Reflector 代码,证明文件读写完就关闭的。
你的杀毒软件关闭了没有?
Public Shared Function ReadAllText(ByVal path As String, ByVal encoding As Encoding) As String
Using reader As StreamReader = New StreamReader(path, encoding)
Return reader.ReadToEnd
End Using
End Function
Public Shared Sub WriteAllText(ByVal file As String, ByVal [text] As String, ByVal append As Boolean, ByVal encoding As Encoding)
FileSystem.CheckFilePathTrailingSeparator(file, "file")
Dim writer As StreamWriter = Nothing
Try
If (append AndAlso File.Exists(file)) Then
Dim reader As StreamReader = Nothing
Try
reader = New StreamReader(file, encoding, True)
Dim buffer As Char() = New Char(10 - 1) {}
reader.Read(buffer, 0, 10)
encoding = reader.CurrentEncoding
Catch exception As IOException
Finally
If (Not reader Is Nothing) Then
reader.Close
End If
End Try
End If
writer = New StreamWriter(file, append, encoding)
writer.Write([text])
Finally
If (Not writer Is Nothing) Then
writer.Close
End If
End Try
End Sub