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