![](/img/trans.png)
[英]FileStream Reader and writer at the same time when file.exe is closing
[英]access denied when saving a file.exe to my documents
嗨,我想創建一個程序,將文件保存到我的文檔\\測試。 該文件是.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");
你的兩個例子不一樣。 您的第一個示例不起作用,因為System.IO.Directory.CreateDirectory
已經創建了名為test
的目錄。 您無法覆蓋該目錄,就像它是一個文件一樣。 為了使您的示例1表現得像示例二:
System.IO.Directory.CreateDirectory(path2)
File.WriteAllBytes(path2 + @"\" + "text.txt", myfile)
我從來沒有試過在exe文件中寫,但你已經嘗試過設置權限? 我不知道在c#exisist中是否有一些方法可以做到,但肯定存在“exec”,所以你可以用它來發送chmod命令
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.