Java I/O How to - Read unsigned byte from file








Question

We would like to know how to read unsigned byte from file.

Answer

  //  w  ww. ja v a 2 s.  co m

import java.io.DataInputStream;
import java.io.FileInputStream;

public class Main {

  public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/UnsignedByte.txt");
    DataInputStream din = new DataInputStream(fin);

    int i = din.readUnsignedByte();
    System.out.println("Unsinged byte value : " + i);
    din.close();
  }
}