public static byte[] readAllBytes(Path path) throws IOException {
  try (SeekableByteChannel sbc=Files.newByteChannel(path);InputStream in=Channels.newInputStream(sbc)){
    long size=sbc.size();
    if (size > (long)MAX_BUFFER_SIZE)     throw new OutOfMemoryError("Required array size too large");
    return read(in,(int)size);
  }
 }

public static byte [ ] readAllBytes ( Path path ) throws IOException { try ( SeekableByteChannel sbc = Files . newByteChannel ( path ) ; InputStream in = Channels . newInputStream ( sbc ) ) { long size = sbc . size ( ) ; if ( size > ( long ) MAX_BUFFER_SIZE ) throw new OutOfMemoryError ( "Required array size too large" ) ; return read ( in , ( int ) size ) ; } }
reads all the bytes from a file . the method ensures that the file is closed when all bytes have been read or an i / o error , or other runtime exception , is thrown . < p > note that this method is intended for simple cases where it is convenient to read all bytes into a byte array . it is not intended for reading in large files .
