如何将数据追加到一个二进制文件?如何将、二进制文件、数据

2023-09-02 01:50:12 作者:愛情,不屬於我。

我要我要附加的数据块在文件中到底哪一个二进制文件,我怎么能使用C#和.NET实现这一目标?也有什么注意事项写入二进制文件的末尾时要采取?非常感谢您的帮助。

解决方案

 私有静态无效AppendData(字符串文件名,诠释intData,串StringData是byte []的lotsOfData)
{
    使用(VAR FILESTREAM =新的FileStream(文件名,FileMode.Append,FileAccess.Write,FileShare.None))
    使用(VAR体重=新的BinaryWriter(FILESTREAM))
    {
        bw.Write(intData);
        bw.Write(StringData是);
        bw.Write(lotsOfData);
    }
}
 

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 are there any considerations to take 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);
    }
}