Read one byte from a file in Java
Description
The following code shows how to read one byte from a file.
Example
//www . ja va2 s. c o m
import java.io.FileInputStream;
public class Main {
public static void main(String[] argv) throws Exception {
FileInputStream file = null;
file = new FileInputStream("main.java");
byte x = (byte) file.read();
System.out.println(x);
file.close();
}
}
The code above generates the following result.