![](/img/trans.png)
[英]File.Copy "The process cannot access the file <filename> because it is being used by another process
[英]File.Copy prevents File.WriteAllText - The process cannot access the file because it is being used by another process
我有一個循環
fileName
重命名為“delete_me”(成功)...然后我試圖 append 一個字符串到那個新重命名的文件,但我不能......
The process cannot access the file 'delete_me.txt' because it is being used by another process.
File.Delete("delete_me.txt");
File.Copy(fileName, "delete_me.txt");
File.WriteAllText("delete_me.txt", "some string");
我知道有一些Dispose()
和Close()
方法可以掛在File.Create()
的后面,但這似乎不適用於File.Copy()
?
有任何想法嗎?
我試過GC.Collect()
但仍然得到同樣的錯誤。
基於MS 文檔
public static void Copy (string sourceFileName, string destFileName);
sourceFileName
要復制的文件。
destFileName
目標文件的名稱。 這不能是目錄或現有文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.