public byte [ ] getBytes ( ) throws IOException { InputStream input = getInputStream ( ) ; ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; final byte [ ] buffer = new byte [ DEFAULT_BUFFER_SIZE ] ; int len ; try { while ( ( len = input . read ( buffer ) ) != - 1 ) { output . write ( buffer , 0 , len ) ; } } finally { try { output . close ( ) ; } catch ( IOException e ) { // ignore } try { input . close ( ) ; } catch ( IOException e ) { // ignore } } return output . toByteArray ( ) ; }
Returns the contents of the file in a byte array . Can not use a large array of memory than the JVM Heap deal .