2014-12-02 77 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