我用filestream的readallbyte读取文件并输出到byte数组中,但是当读取大于1MB的文件时,数据长度就会超出数组的最大长度,请问应该怎么解决这个问题

解决方案 »

  1.   

    怎么实现的?我没有找到中断readallbytes的方法
      

  2.   

    获取文件长度FileInfo.Length Read 带参数取
      

  3.   

    先别定义大小,
                Byte[] bt;
                bt=File.ReadAllBytes(filepath);
      

  4.   

    byte[] bBuffer = new byte[0x10000];//create 64k buffer
    int nRealRead;
    do
    {
        nRealRead = yourFS.Read( bBuffer, 0, bBuffer.Length );
        //Show data using "bBuffer );
    }
    while( nRealRead == bBuffer.Length );
      

  5.   

    ReadByte 从文件中读取一个字节,并将读取位置提升一个字节。
    Read 从流中读取字节块并将该数据写入给定缓冲区中。
    using System;
    using System.IO;class FSRead
    {
        public static void Main()
        {
            //Create a file stream from an existing file.
            FileInfo fi=new FileInfo("c:\\csc.txt");       
            FileStream fs=fi.OpenRead();
            
            //Read 100 bytes into an array from the specified file.
            int nBytes=100;
            byte[] ByteArray=new byte[nBytes];
            int nBytesRead=fs.Read(ByteArray, 0, nBytes);
            Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());
        }
    }
      

  6.   

    "大于1MB的文件时,数据长度就会超出数组的最大长度"----为什么是1M?你自己设的吧?典型读法:FileStream filestm = new FileStream("path",FileMode.Open);
    byte[] buffer = new byte[(int)filestm.Length];
    int iOffset = 0, iCount = buffer.Length;
    while (iCount > 0)
    {
         int m = filestm.Read(buffer,iOffset,iCount);
         if (m <= 0)
              break;
         iOffset += m;
         iCount -= m;
    }
      

  7.   

    我是这样定义数组的 byte[] reader = File.ReadAllBytes(fileName1);
    但是当打开一个大于1MB的文件,就会提示超出了数组的范围(1000000)
      

  8.   

    原来是只能显示那么多.可以打开大文件,但是速度很慢.我是将十六进制代码和char值用stringbuilder同时输出到richtextbox里面,有什么方法可以使速度快一些吗?