How to write into an existing textfile in windows phone?

末鹿安然 提交于 2019-12-12 03:25:55

问题


If this is the code in opening a textfile "word.txt" in my solution explorer.

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

How do i write and append in the existing textfile?


回答1:


Here is an example

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

    }


来源:https://stackoverflow.com/questions/18672102/how-to-write-into-an-existing-textfile-in-windows-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!