public static ByteBuffer readFile(File file) throws IOException {
  FileInputStream fis=new FileInputStream(file);
  FileChannel fc=fis.getChannel();
  ByteBuffer readBuffer=ByteBuffer.allocate((int)fc.size());
  fc.read(readBuffer);
  fis.close();
  readBuffer.rewind();
  return readBuffer;
}

public static ByteBuffer readFile ( File file ) throws IOException { FileInputStream fis = new FileInputStream ( file ) ; FileChannel fc = fis . getChannel ( ) ; ByteBuffer readBuffer = ByteBuffer . allocate ( ( int ) fc . size ( ) ) ; fc . read ( readBuffer ) ; fis . close ( ) ; readBuffer . rewind ( ) ; return readBuffer ; }
new nio based method to read the contents of a file as byte array . only files up to size integer . max_int can be read . the byte buffer is rewinded when returned .
