当程序读一个很大文件时就会报错java.lang.OutOfMemoryError
不知道是文件里面数据有误还是程序内存泄漏了,请问各位高手如何定位这个问题啊?
代码里面new的数组我都单独try了这个错误,但是它都没有捕获,不知道错在哪里,头大了!!!
文件是二进制的。
谢谢,谢谢!

解决方案 »

  1.   

    启动的时候设置内存足够大...
    你的情况是确实内存用尽..
    这是系统错误.应用是根本catch不到的..
      

  2.   

    打开文件时,是要读进内存的,
    建议 分批读取,用java.io.RandomAccessFile 看看
      

  3.   

    可能一次将file读到内存,内存就满了,可以使用Buffer读文件
      

  4.   

    分段读:        try {
                int bytesum = 0;
                int byteread = 0;
                File oldfile = new File( oldPath );
                if ( oldfile.exists() ) {
                    InputStream inStream = new FileInputStream( oldPath ); 
                    byte[] buffer = new byte[1444];
                    int length;
                    while ( ( byteread = inStream.read( buffer ) ) != - 1 ) {
    //......
                    }
                    inStream.close();
                }
            } catch ( Exception e ) {
                System.out.println( " Message error!" );
                e.printStackTrace();        }
      

  5.   

    out of memory嘛经常见到,关键是你的内存太少了