把d:\333.doc 复制到d:\444.doc  我用这种文件流的方法,不用file.copy 为什么复制完了以后444.doc 变成乱码的了?本人还是新手,请多指教.string c;Stream datastream = new FileStream("d:\\444.doc", FileMode.Create);
        StreamWriter nfile = new StreamWriter(datastream, Encoding.ASCII);
        using (StreamReader ofile = new StreamReader("d:\\333.doc", Encoding.ASCII))
        {
            while ((c=ofile.ReadLine())!=null)
            {
                //Console.WriteLine(ofile.ReadLine().Length);
                nfile.WriteLine(c);
                Console.WriteLine(c);
            }
            ofile.Close();
            nfile.Close();
        }

解决方案 »

  1.   

    把你的Encoding这个参数都去掉,用你默认的Encoding就不会乱码了。
      

  2.   

    我是都去掉了啊,
    Stream datastream = new FileStream("d:\\444.doc", FileMode.Create);
            StreamWriter nfile = new StreamWriter(datastream);
            using (StreamReader ofile = new StreamReader("d:\\333.doc"))
            {
                while ((c=ofile.ReadLine())!=null)
                {
                    //Console.WriteLine(ofile.ReadLine().Length);
                    nfile.WriteLine(c);
                    Console.WriteLine(c);
                }
                ofile.Close();
                nfile.Close();
            }
    变成这样了
    但是还是乱码,而且一个24k 的文件复制完了以后变成28k ,比原来还多了4k 呵
      

  3.   

    恩,Word本身是带格式的。
    所以直接用StreamReader不行,你换一个BinaryReader看看。
      

  4.   

    Using fs As IO.FileStream = New IO.FileStream("d:\2.doc", IO.FileMode.Create)
                Using f As IO.FileStream = New IO.FileStream("d:\1.doc", IO.FileMode.Open)
                    Dim byteData(1024) As Byte
                    Dim intLen As Integer = f.Read(byteData, 0, byteData.Length)
                    While intLen > 0
                        fs.Write(byteData, 0, intLen)
                        intLen = f.Read(byteData, 0, byteData.Length)
                    End While
                End Using
            End Using
      

  5.   


    using( FileStream fs = new FileStream("d:\2.doc", FileMode.Create) )
    {
       using( FileStream f = new FileStream("d:\1.doc", FileMode.Open) )
       {
           byte[1024] byteData;
           int length = f.Read(byteData, 0, byteData.Length);
           while(length > 0)
           {
              fs.Write(byteData, 0, length);
              length = f.Read(byteData, 0, byteData.Length);
           }
       }
    }
      

  6.   

    StreamWriter、StreamReader是用来读写纯文本文件的
    5楼正解,但缓冲区大小1024太小了,内部缓冲区大小是4096吧~
      

  7.   

    StreamReader ofile = new StreamReader("d:\\aa.doc", Encoding.GetEncoding("gb2312"));
                FileStream fs = new FileStream("d:\\bb.doc", FileMode.Create);
                StreamWriter wFile = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
                wFile.Write(ofile.ReadToEnd());
                ofile.Close();
                wFile.Close();
      

  8.   

    viena 眼睛好利阿。我随手写的1024是小了点。
      

  9.   

    ASCII的字节范围是0-127,大于127的字节不能处理,所以成乱码了。