BinaryReader br=new BinaryReader(File.Open(@"c:/xxx.mp3",FileMode.Open));
while(br.PeekChar()!=-1)
{
Console.Write(br.Read());
}
xxx.mp3是一个大概2M左右的MP3文件
每次运行都报:缓冲区益处
请哪为大哥小弟是什么道理,有什么办法解决

解决方案 »

  1.   

    using System;
    using System.IO;
    class MyStream 
    {
        private const string FILE_NAME = "Test.data";
        public static void Main(String[] args) 
        {
            // Create the new, empty data file.
            if (File.Exists(FILE_NAME)) 
            {
                Console.WriteLine("{0} already exists!", FILE_NAME);
                return;
            }
            FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew);
            // Create the writer for data.
            BinaryWriter w = new BinaryWriter(fs);
            // Write data to Test.data.
            for (int i = 0; i < 11; i++) 
            {
                w.Write( (int) i);
            }
            w.Close();
            fs.Close();
            // Create the reader for data.
            fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);
            BinaryReader r = new BinaryReader(fs);
            // Read data from Test.data.
            for (int i = 0; i < 11; i++) 
            {
                Console.WriteLine(r.ReadInt32());
            }
            w.Close();
        }
    }
      

  2.   

    是在windows下么?是的话 文件名为@"c:\xxx.mp3"
      

  3.   

    但是只要用BinaryStream读稍微大点的文件。我读的是2M的文件,他就会说:
    未处理的“System.ArgumentException”类型的异常出现在 mscorlib.dll 中。其他信息: 转换缓冲区溢出。
      

  4.   

    溢出异常应该是针对PeekChar()的吧, 一个一个byte读取的时候,if读到的不是一个valide character,then抛出这个异常就是正常的了。
    读文件有很多其他好方法啊,比如readbyte()...
    just for reference, good luck...
      

  5.   

    但是用readbyte怎么来控制循环次数呢