/**
 * 
 */
package homework0;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author s Hershkop
 * 
 * read a file and count number of lines and characters
 * 
 * name of file should come in as command line arg
 *
 */
public class Example3 {

    
    
    public static void main(String[] args) {
        System.out.println("will attempt to open : " + args[0]);
        
        try{
            
        int countChars = 0, countLines = 0;
        BufferedReader bfin = new BufferedReader(new FileReader(args[0]));
        
        String readline;
        
        while( (readline = bfin.readLine()) != null)
        {
            countLines++;
             
            countChars += readline.length();
            
        }
        
        bfin.close();
        
        System.out.println("number of lines: " + countLines);
        System.out.println("number of chars: " + countChars);
        
        
        }catch(FileNotFoundException fnf){
            System.out.println("File not found " + fnf);
            System.exit(-1);
        }catch(IOException ioe){
            ioe.printStackTrace();
            System.exit(-2);
        }
    }
}
