嗨,我想创建一个将文件保存到我的文档\测试的程序。该文件是.exe。由于某种未知原因,我收到拒绝访问错误,当我测试程序试图保存 .txt 文件(使用 StreamWriter)时,程序运行没有任何问题。请帮帮我。
以下代码抛出错误
byte[] myfile = Properties.Resources.WallPaper;
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string path2 = path + @"\" + "test";
System.IO.Directory.CreateDirectory(path2);
File.WriteAllBytes(path2, myfile);
保存 .txt 文件时,以下代码可以正常工作
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string path2 = path + @"\" + "test";
System.IO.Directory.CreateDirectory(path2);
StreamWriter file = new StreamWriter(path2 + @"\" + "text.txt");