Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append array of bytes to the existed 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?

like image 852
Nagg Avatar asked Dec 30 '12 16:12

Nagg


1 Answers

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);
}
like image 92
Jim O'Neil Avatar answered Nov 05 '22 21:11

Jim O'Neil