List of utility methods to do Binary File Read
byte[] | read(File file) Read data from file byte[] bytes = null; try { InputStream ins = new BufferedInputStream(new FileInputStream( file)); bytes = new byte[ins.available()]; ins.read(bytes); ins.close(); } catch (Exception ex) { ... |
byte[] | read(String fileName) Read data from file byte[] bytes = null; try { if (StringUtil.isEmpty(fileName)) { return null; InputStream in = new BufferedInputStream(new FileInputStream( fileName)); bytes = new byte[in.available()]; ... |
String | readFile(File f) Reads the contents of a text file and returns them in a string FileInputStream stream = new FileInputStream(f); try { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } finally { stream.close(); ... |
String | readFile(File file) read File FileInputStream in = null; try { in = new FileInputStream(file); byte[] b = new byte[in.available()]; in.read(b, 0, b.length); return new String(b); } finally { if (in != null) { ... |
byte[] | readFile(File file, int size) read File return readFile(new FileInputStream(file), size); |
byte[] | readResource(String resourceName) Read a file from classpath as byte byte[] bytes = null; try { InputStream ins = FileUtil.class .getResourceAsStream(resourceName); bytes = new byte[ins.available()]; ins.read(bytes); ins.close(); } catch (Exception ex) { ... |