我想寫一些數據到我的項目(本地文件到項目)中的現有文件。我用下面的代碼使用StreamWriter後文件空白
Uri path = new Uri(@"Notes.txt", UriKind.Relative);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (StreamWriter writefile = new StreamWriter(new IsolatedStorageFileStream(path.ToString(), FileMode.Append, FileAccess.Write,myIsolatedStorage)))
{
writefile.WriteLine("hi");
writefile.Flush();
writefile.Dispose();
}
}
在執行program.However文件是空白的,不包含任何數據沒有例外/錯誤。
我已經將文件的構建操作設置爲'resource',將內容設置爲'copy if newer'。 只是爲了檢查,我刪除了文件並進行了測試,但它仍然沒有給出任何異常,儘管我試圖在追加模式下打開。
編輯:我在我的開發環境中打開文件來檢查。不過,我後來使用ISETool.exe來檢查文件。但該文件根本沒有創建!以下是更新後的代碼我使用:
Uri path = new Uri(@"Notes.txt", UriKind.Relative);
using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
using (var stream = new IsolatedStorageFileStream(path.ToString(), FileMode.OpenOrCreate, FileAccess.Write, myIsolatedStorage))
using (var writefile = new StreamWriter(stream))
{
writefile.WriteLine("hi");
}
你是如何檢查是否該文件有任何數據? – 2013-04-11 03:34:12
我手動打開文件,手動檢查任何數據 – user2210060 2013-04-11 03:43:17
從哪裏?您是否使用IsolatedStorageTool從應用程序下載它? – 2013-04-11 03:44:37