public static byte [ ] readBytes ( final File file , final int count ) throws IOException { checkExists ( file ) ; checkIsFile ( file ) ; long numToRead = file . length ( ) ; if ( numToRead >= Integer . MAX_VALUE ) { throw new IOException ( "File is larger then max array size" ) ; } if ( count > NEGATIVE_ONE && count < numToRead ) { numToRead = count ; } byte [ ] bytes = new byte [ ( int ) numToRead ] ; RandomAccessFile randomAccessFile = new RandomAccessFile ( file , "r" ) ; randomAccessFile . readFully ( bytes ) ; randomAccessFile . close ( ) ; return bytes ; }
Read file and returns byte array with contents .