Read a file int by int in Java

Description

The following code shows how to read a file int by int.

Example


//from  ww w.j  a va  2 s . c  o m
import java.io.FileInputStream;

class FileInputStreamDemo {

  public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream("Main.java");

    // Read and display data
    int i;
    while ((i = fis.read()) != -1) {
      System.out.println(i);
    }

    fis.close();

  }
}




















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