0

如果这是在我的解决方案资源管理器中打开文本文件“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;
            }
        }

我如何在现有的文本文件中写入和追加?

4

1 回答 1

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

    }
于 2013-09-22T15:16:32.807 回答