How to read a byte primitive value from file using readByte method of DataInputStream class. - Java File Path IO

Java examples for File Path IO:DataInputStream

Description

How to read a byte primitive value from file using readByte method of DataInputStream class.

Demo Code


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
public class Main {
 
  public static void main(String[] args) {
   /*from ww w.  j a va  2  s.com*/
    String strFilePath = "C:/Folder/Byte.txt";
   
    try
    {
      FileInputStream fin = new FileInputStream(strFilePath);
      DataInputStream din = new DataInputStream(fin);
      byte b = din.readByte();
      System.out.println("byte : " + b);
      din.close();
       
    }
    catch(FileNotFoundException fe)
    {
      System.out.println("FileNotFoundException : " + fe);
    }
    catch(IOException ioe)
    {
      System.out.println("IOException : " + ioe);
    }
  }
}

Result


Related Tutorials