如何将数据附加到二进制文件? [英] How to append data to a binary file?

查看:62
本文介绍了如何将数据附加到二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二进制文件,要在文件末尾附加一个数据块,如何使用C#和.net做到这一点?在写入二进制文件的末尾时还需要考虑什么?非常感谢您的帮助。

I have a binary file to which I want to append a chunk of data at the end of the file, how can I achieve this using C# and .net? Also is there anything to consider when writing to the end of a binary file? Thanks a lot for your help.

推荐答案

private static void AppendData(string filename, int intData, string stringData, byte[] lotsOfData)
{
    using (var fileStream = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.None))
    using (var bw = new BinaryWriter(fileStream))
    {
        bw.Write(intData);
        bw.Write(stringData);
        bw.Write(lotsOfData);
    }
}

这篇关于如何将数据附加到二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆