在Windows Phone 7中,我正在尝试写入文件,然后尝试从文件中读取文件,但在阅读时会给出以下例外情况。
public static void writeToFile(String videoUrl)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
store.CreateDirectory("MyFolder");
IsolatedStorageFileStream stream = new IsolatedStorageFileStream("MyFolder\\data.txt", FileMode.Append,
FileAccess.Write, store);
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(videoUrl);
}
public static void readFromFile()
{
try
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream stream = new IsolatedStorageFileStream("MyFolder\\data.txt", FileMode.Open,
store);
StreamReader reader = new StreamReader(stream);
string line;
while ((line = reader.ReadLine()) != null)
{
Debug.WriteLine("kkkkkk-----------------" + line); // Write to console.
}
}
catch (Exception ex)
{
Debug.WriteLine("ESPNGoalsUtil::readFromFile : " + ex.ToString());
}
}
例外:
System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, IsolatedStorageFile isf)
at ESPNGoals.Utility.ESPNGoalsUtil.readFromFile()
我正在编写文件,然后以相同的方法读取文件而不关闭模拟器。