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.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip