0
在windows phone 7中,我試圖寫入一個文件,然後嘗試從一個文件中讀取數據,但是在讀取它時給出了下面的異常。IsolatedStorageFile給出異常
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()
我寫的文件,然後讀取相同的方法文件,而不是關閉模擬器。