public static byte[] readFile(File file){
  RandomAccessFile ra=null;
  try {
    ra=new RandomAccessFile(file,"r");
    long len=ra.length();
    if (len >= Integer.MAX_VALUE) {
      throw new RuntimeException("File " + file.getPath() + " is too large");
    }
    byte[] buffer=new byte[(int)len];
    ra.readFully(buffer);
    ra.close();
    return buffer;
  }
 catch (  IOException e) {
    throw new RuntimeException("Error reading from file " + file,e);
  }
 finally {
    if (ra != null) {
      try {
        ra.close();
      }
 catch (      IOException e) {
      }
    }
  }
}

public static byte [ ] readFile ( File file ) { RandomAccessFile ra = null ; try { ra = new RandomAccessFile ( file , "r" ) ; long len = ra . length ( ) ; if ( len >= Integer . MAX_VALUE ) { throw new RuntimeException ( "File " + file . getPath ( ) + " is too large" ) ; } byte [ ] buffer = new byte [ ( int ) len ] ; ra . readFully ( buffer ) ; ra . close ( ) ; return buffer ; } catch ( IOException e ) { throw new RuntimeException ( "Error reading from file " + file , e ) ; } finally { if ( ra != null ) { try { ra . close ( ) ; } catch ( IOException e ) { } } } }
read a file . the maximum file size is integer . max_value .
