2011-06-22 7 views
0

Windows Phone 7では、ファイルに書き込もうとしてファイルから読み込もうとしていますが、読み込み中に以下の例外が発生しています。IsolatedStorageFile except exception

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() 

答えて

0

writeToFileが返却される前にStreamWriterCloseを呼び出す必要があります(コードをusingブロックにラップする方がよい)。

StreamReaderreadFromFileで同じです。