FileStream 抛出 UnauthorizedAccessException - C#
我正在尝试创建 FileStream 但不断收到“UnauthorizedAccessException”,此语句有什么问题?
FileStream fs = new FileStream(@"C:\", FileMode.Create, FileAccess.ReadWrite);
谢谢,
埃蒙
I am trying to create a FileStream but keep getting "UnauthorisedAccessException", what is wrong with this statement?
FileStream fs = new FileStream(@"C:\", FileMode.Create, FileAccess.ReadWrite);
Thanks,
Eamonn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不允许您打开指向C分区根目录的文件流。我想,这不是你想做的。如果要创建文件,请指定文件名。
You are not allowed to open a file stream that points to the root directory of your C partition. I assume, that's not what you want to do. If you want to create a file, than specify a file name.
我认为路径应该是文件名 - “c:\test.txt”而不是位置。
另请注意 c:\ 是否可用,具体取决于可以保护的操作系统(例如在 Vista/Win 7 中)
I think the path should be a filename - "c:\test.txt" rather than the location.
Also watch that c:\ is available, depending on the OS it can be protected (eg in Vista/Win 7)
您正在尝试将目录作为文件打开。
You are trying to open a directory as a file.