本文介绍了如何将字节数组追加到现有的StorageFile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要相应地(在我的Metro应用程序中)按字节块写入文件数据,并且存在一个类FileIO
,其中包含方法AppendTextAsync
和WriteBytesAsync
,但没有需要的AppendBytesAsync
,所以我该如何追加StorageFile
的字节数组?
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
?
推荐答案
此代码似乎对我有用:
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);
}
这篇关于如何将字节数组追加到现有的StorageFile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!