home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / java / nutsandbolts / betaexample / CountFile.java < prev    next >
Encoding:
Java Source  |  1995-11-13  |  498 b   |  24 lines

  1. import java.io.*;
  2.  
  3. class CountFile {
  4.     public static void main(String args[])
  5.     throws java.io.IOException, java.io.FileNotFoundException
  6.     {
  7.         int count = 0;
  8.     InputStream is;
  9.  
  10.         if (args.length == 1)
  11.         is = new FileInputStream(args[0]);
  12.     else
  13.         is = System.in;
  14.     
  15.         while (is.read() != -1)
  16.             count++;
  17.  
  18.     if (args.length == 1)
  19.         System.out.println(args[0] + " has "+ count + " chars.");
  20.     else
  21.         System.out.println("Input has " + count + " chars.");
  22.     }
  23. }
  24.