且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中的特定位置写入数据?

更新时间:2023-10-09 13:37:34

切勿尝试写二进制数据作为字符串,像你一样。这将无法正常工作。写的二进制数据作为二进制数据。您可以使用为代替的StreamWriter 。

Never try to write binary data as strings, like you do. It won't work correctly. Write binary data as binary data. You can use Stream for that instead of StreamWriter.

using (Stream stream = new FileStream(fileName, FileMode.OpenOrCreate))
{
    stream.Seek(1000, SeekOrigin.Begin);
    stream.Write(Data, 0, Data.Length);
}