3

에 허용되지작동 내가 오류가 IsolatedStorageFileStream

당신이 CreateFile 메소드에 의해 반환되는 스트림을 닫지 않았다 때문이다
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      myFileStore.CreateFile(DateTime.Now.Ticks + ".txt"); 
     } 
using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      temp = myFileStore.GetFileNames(); 
      for (int k = 0; k < temp.Length; k++) 
      { 
       IsolatedStorageFileStream file1 = myFileStore.OpenFile(temp[k], FileMode.Open, FileAccess.Read); 
       dataSource.Add(new SampleData() { Name = temp[k], Size = Convert.ToString(Math.Round(Convert.ToDouble(file1.Length)/1024/1024, 1) + " MB") }); 
      } 
     } 

답변

4

!

코드는 다음과 같아야합니다

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    myFileStore.CreateFile(DateTime.Now.Ticks + ".txt").Dispose(); 
} 

또는

using (var myFileStore = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    using(myFileStore.CreateFile(DateTime.Now.Ticks + ".txt")) 
    { 
    } 
} 

그리고 아래 OpenFile에서 같은

.

결론 당신은 항상

합니다 ( using 절 또는 Dispose() 방법을 사용하여) 스트림을 처리한다
관련 문제