从一个文件读取和写入二进制数据到另一个文件

Reading and writing binary data from one to another file

我正在读取一个二进制文件并通过跳过几行写入另一个 CP 437 格式的文件。但是输出文件的大小比原始文件增加了,而且数据也被破坏了。任何有助于确定问题的帮助。

        StreamReader sStreamReader = new StreamReader(@"D:\Denesh\Input.txt");
        string AllData = sStreamReader.ReadToEnd();
        string[] rows = AllData.Split(",".ToCharArray());

        FileStream fileStream = new FileStream(TransLog, FileMode.Open);
        StreamReader streamReader = new StreamReader((Stream)fileStream, Encoding.GetEncoding(437));
        StreamWriter streamWriter = new StreamWriter(outFile, false);
        int num = 0;
        int count = 0;

            while (!streamReader.EndOfStream)
            {
                string tlogline = streamReader.ReadLine();

                if (rows[count] == Convert.ToString(num))
                {
                    ++count;
                }
                else
                {
                    ++num;
                    streamWriter.WriteLine(tlogline, streamReader.CurrentEncoding);
                }
            }

        fileStream.Close();
        streamWriter.Close();

为 streamwriter 添加文件流解决了这个问题。谢谢。