我试图直接用 FileStream 打开 C: 没有成功:
new FileStream("C:", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
System.UnauthorizedAccessException 未处理
Message="拒绝访问路径 'C:\'。"
来源="mscorlib"
堆栈跟踪:
in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) in System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) in System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) in System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) in ReadingMftNewTest.Program.Main(String[] args) in D:\CS\2008\ReadingMftNewTest\ReadingMftNewTest\Program.cs:line 76
请注意,我打开“C:”但错误显示“C:\”,这个斜杠是从哪里来的?:\
有没有机会在不使用CreateFile
API的情况下打开 C:?
我真的不想依赖于 WIN32 API,因为此代码也应该在不支持 WIN32 API 的 Mono 上运行,但可以使用常规 FileStream(Mono 1 Microsoft 0)成功打开设备。