public static byte[] readBytesFromFile(final String filePath) throws IOException {
  final File file=new File(filePath);
  final long length=file.length();
  try (FileInputStream fis=new FileInputStream(file)){
    byte[] val=new byte[(int)length];
    int offset=0;
    int numRead=0;
    while (offset < val.length && (numRead=fis.read(val,offset,val.length - offset)) >= 0) {
      offset+=numRead;
    }
    if (offset < val.length) {
      throw new IOException("Could not completely read file " + filePath);
    }
    return val;
  }
 }

public static byte [ ] readBytesFromFile ( final String filePath ) throws IOException { final File file = new File ( filePath ) ; final long length = file . length ( ) ; try ( FileInputStream fis = new FileInputStream ( file ) ) { byte [ ] val = new byte [ ( int ) length ] ; int offset = 0 ; int numRead = 0 ; while ( offset < val . length && ( numRead = fis . read ( val , offset , val . length - offset ) ) >= 0 ) { offset += numRead ; } if ( offset < val . length ) { throw new IOException ( "Could not completely read file " + filePath ) ; } return val ; } }
read the data from the specified file and return it in a byte array .
