gpt4 book ai didi

c# - 如何将字节数组附加到现有的 StorageFile?

转载 作者:太空狗 更新时间:2023-10-29 21:09:37 25 4
gpt4 key购买 nike

我需要相应地按字节 block 写入文件数据(在我的 Metro 应用程序中)并且有一个类 FileIO 具有方法 AppendTextAsyncWriteBytesAsync 但不需要 AppendBytesAsync 那么如何将字节数组附加到 StorageFile

最佳答案

这段代码似乎对我有用:

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

关于c# - 如何将字节数组附加到现有的 StorageFile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14092488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com