How to append array of bytes to the existed StorageFile?

喜你入骨 提交于 2019-12-06 01:49:13

问题


I need to write to a file data by chunks of bytes consequentially (in my Metro app) and there is a class FileIO with methods AppendTextAsync and WriteBytesAsync but without needed AppendBytesAsync so how can I append an array of bytes to a StorageFile?


回答1:


This code seems to work for me:

String s = "hello";
Byte[] bytes = Encoding.UTF8.GetBytes(s);

using (Stream f = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync
    ("hello.txt", CreationCollisionOption.OpenIfExists))
{
    f.Seek(0, SeekOrigin.End);
    await f.WriteAsync(bytes, 0, bytes.Length);
}


来源:https://stackoverflow.com/questions/14092488/how-to-append-array-of-bytes-to-the-existed-storagefile

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