Reputation: 43
In windows phone 8.1 i want to use streamwriter in text, and appending text to file end. But the text is appended to the beginning of the file. how to appending text to file end?
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///input_category_list.txt"));
using (StreamWriter sWrite = new StreamWriter(await file.OpenStreamForWriteAsync(), System.Text.UTF8Encoding.UTF8))
{
sWrite.WriteLine(write_category_box.Text);
await sWrite.FlushAsync();
}
Upvotes: 1
Views: 1252
Reputation: 11238
There's no need for StreamWriter
in Windows Runtime, you can use FileIO
class (which is easier):
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///input_category_list.txt"));
await FileIO.AppendTextAsync(file, write_category_box.Text, UnicodeEncoding.Utf8);
Upvotes: 4
Reputation: 2528
change your code to this:
new StreamWriter(await file.OpenStreamForWriteAsync(),System.Text.UTF8Encoding.UTF8,true))
if you overrride StreamWriter
constructor, as true
, this will set to append text. Otherwise overwrite it.
Upvotes: 0