2014-12-02 82 views
0

我想在windows phone 8應用程序中讀取和寫入文本文件中的數據。 我試過這個代碼在windows phone 8中寫入文件

IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication(); 
StreamWriter wr = new StreamWriter(new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, isf)); 
wr.WriteLineAsync("Hello"); 
wr.Close(); 

但它什麼也沒做。 請幫我解決這個問題。 謝謝。

+0

你明白了什麼,當你'等待wr.WriteLineAsync( 「你好」);'?我的猜測是你沒有看到任何東西,因爲你在編寫任何東西之前關閉了你的Streamwriter。 – 2014-12-02 10:57:27

+0

看到我的答案在這裏:http://stackoverflow.com/questions/27166253/windows-phone-8-choose-text-file-c-sharp/27168118#27168118它被許多人回答了很多次。 – 2014-12-02 11:10:35

+0

我認爲你必須先谷歌它。有很多幫助。 – 2014-12-02 11:15:51

回答

1

將數據寫入文件:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 

//create new file 
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("myFile.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage))) 
{ 
    string someTextData = "This is some text data to be saved in a new text file in the IsolatedStorage!"; 
    writeFile.WriteLine(someTextData); 
    writeFile.Close(); 
} 

讀數據從文件:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read); 
using (StreamReader reader = new StreamReader(fileStream)) 
{  
    //Visualize the text data in a TextBlock text 
    this.text.Text = reader.ReadLine(); 
} 

通過這個鏈接:http://www.geekchamp.com/tips/all-about-wp7-isolated-storage-read-and-save-text-files

https://www.google.co.in/#q=wp8+isolated+storage+geek

+0

這太好了。但仍然存在一個問題 當我雙擊文本文件>仍然沒有更新。 – 2014-12-02 13:04:07