【问题标题】:File access error - already in use when reading from file (vb.NET 2.0)文件访问错误 - 从文件读取时已在使用 (vb.NET 2.0)
【发布时间】:2012-11-20 23:19:24
【问题描述】:

使用:

Dim fileStream as System.IO.FileStream = System.IO.File.Open(filename, FileMode.Open)

相对于(见行尾):

Dim fileStream as System.IO.FileStream = System.IO.File.Open(filename, FileMode.Open, FileAccess.Read)

Dim fileStream as System.IO.FileStream = System.IO.File.Open(filename, FileMode.Open)
Dim data(fileStream.length) as Byte
fileStream.read(data, 0, fileStream.length)
fileStream.close()

添加FileAccess.Read 标志是否会阻止遇到从文件读取时已在使用异常?

做得更好 - 即使在其他地方打开,您也可以在只读模式下访问吗?

【问题讨论】:

标签: .net file-io


【解决方案1】:

如果您没有使用FileAccess.[Value] 明确指定访问权限,则System.IO.File.Open(...) 函数默认为读/写,从而引发错误。

见:http://msdn.microsoft.com/en-us/library/system.io.file.open.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多