【问题标题】:How to append array of bytes to the existed StorageFile?如何将字节数组附加到现有的 StorageFile?
【发布时间】:2023-03-08 14:10:01
【问题描述】:
我需要依次按字节块写入文件数据(在我的 Metro 应用程序中),并且有一个类 FileIO 带有方法 AppendTextAsync 和 WriteBytesAsync 但不需要 AppendBytesAsync 所以我该如何追加StorageFile?的字节数组?
【问题讨论】:
标签:
c#
windows-8
microsoft-metro
windows-runtime
windows-store-apps
【解决方案1】:
这段代码似乎对我有用:
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);
}