C# 如何在windows phone中写入现有的文本文件?

C# 如何在windows phone中写入现有的文本文件?,c#,windows-phone-7,filestream,file-handling,C#,Windows Phone 7,Filestream,File Handling,如果这是在我的解决方案资源管理器中打开文本文件“word.txt”时的代码 Stream txtStream = Application.GetResourceStream(new Uri("/sample;component/word.txt", UriKind.Relative)).Stream; using (StreamReader sr = new StreamReader(txtStream)) { stri

如果这是在我的解决方案资源管理器中打开文本文件“word.txt”时的代码

       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;
            }
        }
如何在现有文本文件中写入和追加?

以下是一个示例

    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);
            }
        }

    }

。创建StreamWriter,文档将告诉您如何设置附加模式。StreamWriter不够,您无法写入应用程序资源。在修改文件之前,您必须将其复制到独立存储中