我試圖「移動」文件並使用File.Move
對其進行重命名。在我需要將存儲文件添加到特定文件夾之前,它工作正常。由於添加的完整路徑,我可以創建文件,我可以寫信給他們,但只要我嘗試使用File.Move
它給了我「NotSupportedException異常」 的一些我的代碼的一個例子是:使用File.Move時不支持異常
private static void myMethod(String file)
{
File.Delete(file);
using (sout = new StreamWriter(pathStart + "temp.txt"))
{
foreach(Deck deck in deckList)
{
if (deck != null)
{
sout.WriteLine(myString);
sout.WriteLine(otherString);
sout.Flush();
}
}
}
File.Move(pathStart + "temp.txt", pathStart + file);
File.Delete(pathStart + "temp.txt");
}
任何幫助將不勝感激。
'pathStart'的價值是什麼?你應該使用'Path.Combine(pathStart,「temp.txt」)。作爲參考,當sourceFileName或destFileName的格式無效時,將引發異常。(請參閱[documentation](https://msdn.microsoft.com/en-us/library/system.io.file.move( v = vs.110).aspx)) –
pathStart是我的文件系統的複製和粘貼路徑。 – comphunter159
如果你在你的代碼中放置斷點,例如在這一行上 'File.Move(pathStart +「temp.txt」,pathStart + file);'請更新你的代碼,並告訴我們當你使用QuickWatch 'pathStart +「temp.txt」,pathStart + file' – MethodMan