Java FileInputStream.read()

Syntax

FileInputStream.read() has the following syntax.

public int read()  throws IOException

Example

In the following code shows how to use FileInputStream.read() method.


// w  w  w . ja va  2  s .  co  m

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

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

    int i = 0;
    // create new file input stream
    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
      // converts integer to character
      char c = (char) i;
      System.out.print(c);
    }
  }
}