Hi @longevity uyl ,
Welcome to Microsoft Q&A!
Due to the file permissions of UWP, it is recommended that you use ApplicationData.Current.LocalFolder
to access files in the folder.
Use OpenStreamForWriteAsync to open stream and use WriteAsync
to write binary data to file end.
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile saveFile = await localFolder.CreateFileAsync("FileIOtest.txt", CreationCollisionOption.OpenIfExists);
await FileIO.AppendTextAsync(saveFile, "hello world");
String s = "binary data";
Byte[] bytes = Encoding.UTF8.GetBytes(s);
using (Stream stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync
("FileIOtest.txt", CreationCollisionOption.OpenIfExists))
{
stream.Seek(0, SeekOrigin.End);
await stream.WriteAsync(bytes, 0, bytes.Length);
}
Thank you.