2013-09-07 1 views
0

내 솔루션 탐색기에서 "word.txt"텍스트 파일을 여는 코드입니다.Windows phone에서 기존 텍스트 파일에 쓰는 방법은 무엇입니까?

 Stream txtStream = Application.GetResourceStream(new Uri("/sample;component/word.txt", UriKind.Relative)).Stream; 

     using (StreamReader sr = new StreamReader(txtStream)) 
     { 
      string jon; 
      while (!sr.EndOfStream) 
      { 
       jon = sr.ReadLine(); 
       mylistbox.ItemSource = jon; 
      } 
     } 

어떻게하면 기존 텍스트 파일에 쓰고 추가 할 수 있습니까?

+0

['StreamWriter' (http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx). –

+0

StreamWriter를 만들면 문서가 추가 모드를 설정하는 방법을 알려줍니다. – miltonb

+0

StreamWriter로 충분하지 않습니다. 응용 프로그램 리소스에 쓸 수 없습니다. 파일을 수정하기 전에 격리 된 저장소로 파일을 복사해야합니다. –

답변

0

여기서 예를이다

public static void WriteBackgroundSetting(string currentBackground) 
    { 
     const string fileName = "RecipeHub.txt"; 
     using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      if(myIsolatedStorage.FileExists(fileName)) 
       myIsolatedStorage.DeleteFile(fileName); 
      var stream = myIsolatedStorage.CreateFile(fileName); 
      using (StreamWriter isoStream = new StreamWriter(stream)) 
      { 
       isoStream.WriteLine(currentBackground); 
      } 
     } 

    }