当前位置:   article > 正文

The process cannot access the file XXX because it is being used by another process_the process cannot access the file 'e:\陈吉的框架学习\整洁架

the process cannot access the file 'e:\陈吉的框架学习\整洁架构\dog\dog.httpa

如下代码

每次新建文件的时候总是报错

 

The process cannot access the file 'D:\errorlog\2011年7月23日.txt' because it is being used by another process. 

 

Public Sub writelog(ByVal message As String, ByVal path As String)
        Dim writer As StreamWriter
        If File.Exists(path) Then

        Else
            File.Create(path)

        End If
        Dim logfile As FileInfo = New FileInfo(path)

        writer = File.AppendText(path)

        writer.WriteLine(message)
        writer.Flush()

        writer.Close()

    End Sub

 

经过尝试,原因是黄色代码的位置出现了问题。

file.creat()命令执行后,并不会释放资源,造成后边streamwriter访问被独占。

解决办法也简单改成

File.Create(path).close() 即可。

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/215967
推荐阅读
相关标签
  

闽ICP备14008679号