在C#中读写二进制文件

我已经按照以下代码使用C#读取了一个二进制文件。然后,我尝试将此二进制数据写入另一个二进制文件。但是我发现,当我在Winmerge中打开这两个文件时,两个二进制文件都存在差异。即读取文件和写入文件。 您能否建议我仅读取文件并重写为什么会有区别?

       string fileNameWithPath_ = "1.pwpmi";
       string newfileNameWithPath_ = "2.pwpmi";

        System.IO.FileStream fileStream = new System.IO.FileStream(fileNameWithPath_, System.IO.FileMode.Open,
            System.IO.FileAccess.Read);
        System.IO.BinaryReader binReader = new System.IO.BinaryReader(fileStream, Encoding.ASCII);


        char[] chararr = new char[fileStream.Length];

        chararr = binReader.ReadChars((int)fileStream.Length);
        byte[] buffer = binReader.ReadBytes((int)fileStream.Length);

        byte[] bytes = new byte[fileStream.Length];
        fileStream.Read(bytes,0, (int)fileStream.Length);

        byte[] fileBytes = System.IO.File.ReadAllBytes(fileNameWithPath_);
        string stringbyte1 = Encoding.ASCII.GetString(fileBytes);

        binReader.Close();
        fileStream.Close();
        System.IO.BinaryWriter binWriter =
        new System.IO.BinaryWriter(System.IO.File.Open(newfileNameWithPath_, System.IO.FileMode.Create));
        binWriter.Flush();
        binWriter.Write(stringbyte1);
        binWriter.Close();
评论