Java FileInputStream read byte from file

Description

Java FileInputStream read byte from file

import java.io.FileInputStream;
import java.io.IOException;

public class Main {
  public static void main(String[] args) {

    try (FileInputStream fin = new FileInputStream("Main.java")) {
      byte byteData;
      while ((byteData = (byte) fin.read()) != -1) {
        System.out.print((char) byteData);
      }// w  ww .  j av  a  2s .  co m
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}



PreviousNext

Related