Java I/O How to - Create Stream from file Name








Question

We would like to know how to create Stream from file Name.

Answer

   /*from   w w w  .  j  a  va 2s  . c  om*/


import java.io.FileInputStream;

class FileInputStreamDemo {

  public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);

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

    fis.close();

  }
}