您的位置:首页 > 其它

WP8用户独立存储空间中文件的创建和读取

2014-12-23 10:56 357 查看
private string ReadFile(string fileName) //读文件
{
string text;
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isolatedStorageFile.FileExists(fileName))
{
isolatedStorageFile.DeleteFile(fileName);
}
using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.OpenFile(fileName, FileMode.Open))
{
using (StreamReader streamReader = new StreamReader(isolatedStorageFileStream))
{
text = streamReader.ReadToEnd();
}

}
}
return text;
}

public void writeFile(String fileName, String text)  // 写文件
{
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
lock(_readLock)
{
using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.CreateFile(fileName))
{

using (StreamWriter streamWriter = new StreamWriter(isolatedStorageFileStream))
{
streamWriter.Write(text);
}
isolatedStorageFileStream.Close();
isolatedStorageFileStream.Dispose();
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐