public static byte [ ] toByteArray ( final File tmpFile ) throws IOException { byte [ ] data = null ; if ( tmpFile . exists ( ) && ! tmpFile . isDirectory ( ) ) { try ( BufferedInputStream bis = new BufferedInputStream ( new FileInputStream ( tmpFile ) ) ; ByteArrayOutputStream bos = new ByteArrayOutputStream ( FileConst . KILOBYTE ) ; ) { StreamExtensions . writeInputStreamToOutputStream ( bis , bos ) ; data = bos . toByteArray ( ) ; } } return data ; }
Get a byte array from the given file .