【问题标题】:How to append array of bytes to the existed StorageFile?如何将字节数组附加到现有的 StorageFile?
【发布时间】:2023-03-08 14:10:01
【问题描述】:

我需要依次按字节块写入文件数据(在我的 Metro 应用程序中),并且有一个类 FileIO 带有方法 AppendTextAsyncWriteBytesAsync 但不需要 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);
    }
    

    【讨论】:

    猜你喜欢
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 2015-03-10
    • 2020-10-02
    • 2015-12-10
    • 1970-01-01
    相关资源
    最近更新 更多