资深用户,当我遇到此错误时,尝试使用System.IO从Visual C#中的控制台应用程序写入文件:(UnauthorizedAccessException unhandled
我正在观看的课件中不存在)。我知道这是一个非常简单的问题,已经在msdn.com上寻找了解决方案,但我所能找到的只是我的问题是安全错误或System.IO错误,与如何解决该问题无关。
这是代码:
string someText = "I want to write this to a text file!";
File.WriteAllText(@"C:\Users\Keagan\Desktop\
C#projects\UnderstandingNamespaces", someText);
问候K.Roe
我遇到了完全相同的问题。您有两种解决方案:
第一个:确保您对该文件夹具有完全权限。
Go to folder -> Right click -> Properties -> Security Tab -> Select user -> Edit -> Allow Full Control.
第二种解决方案(最有可能):
string someText = "I want to write this to a text file!";
确保someText
变量包含扩展名的文件名。例如:MyFile.txt
或类似的东西。除此之外,请确保您filePath
是正确的。
我遇到了同样的问题,但是我不知道为什么Visual Studio会抛出这个奇怪的异常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句