【发布时间】:2012-08-20 20:19:36
【问题描述】:
我正在使用 Windows Phone 7.5 中的独立存储。我正在尝试从文件中读取一些文本。但调试器说,IsolatedStorageFileStream 上不允许该操作。为什么?
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("info.dat", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string textFile = fileReader.ReadLine();
//Write the contents of the file to the MEssageBlock on the page.
MessageBox.Show(textFile);
fileReader.Close();
更新我的新代码
object _syncObject = new object();
lock (_syncObject)
{
using (var fileStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (FileStream stream = new FileStream("/info.dat", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (var reader = new StreamReader(stream))
{
string textFile = reader.ReadLine();
MessageBox.Show(textFile);
}
}
}
}
}
【问题讨论】:
-
请显示完整的堆栈跟踪。是在 IsolatedStorageFileStream 构造函数中,还是在您尝试读取一行时?
-
@jon-skeet 当我初始化'fileReader'时;
标签: c# windows-phone-7