OnJava8-Examples/onjava/BinaryFile.java
Bruce Eckel bc0026c3e1 Radically reorganized
Plus many new examples in "streams" chapter.
2015-11-11 20:20:04 -08:00

20 lines
510 B
Java

// onjava/BinaryFile.java
// Utility for reading files in binary form.
package onjava;
import java.io.*;
public class BinaryFile {
public static byte[] read(File bFile) throws IOException{
try(BufferedInputStream bf = new BufferedInputStream(
new FileInputStream(bFile))) {
byte[] data = new byte[bf.available()];
bf.read(data);
return data;
}
}
public static byte[]
read(String bFile) throws IOException {
return read(new File(bFile).getAbsoluteFile());
}
}