Friday, March 18, 2011

How to display a text file on console

The following sample type itself to the console.


/******************************************************************************
* File : Typer.java
* Author : http://java.macteki.com/
* Description :
*   Display the contents of a text file.
******************************************************************************/

public class Typer
{
  public static void main(String[] args) throws Exception
  {
    java.io.BufferedReader br=new java.io.BufferedReader(
      new java.io.FileReader("Typer.java"));
   
    String line=null;
    while ((line=br.readLine())!=null)     
    {
      System.out.println(line);
    }
  }
}

No comments:

Post a Comment