import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.FileNotFoundException;

public class Lab1{
	private String filename;
	
	Lab1(){
		filename = " ";
	}

	public int readFile(File file){
		int read = 0;		

		/* Try to open a file. An exception is thrown if the given file 
 		 * does not exist */		
		try{
			/* Opening file stream */
			FileInputStream fin = new FileInputStream(file); 

		
			/* Read the file 1 byte a time */
			while(fin.read() != -1){
				read++;
			}

			/* Closing the file stream */
			fin.close();
		}	
		
		
		/* Catch the exception that is thrown when the file specified in the 
		 * parameter is not found */
		catch(FileNotFoundException fnfe){
			System.out.println("File does not exit");
			return -1;			
		}

		/* Catch the exception that is thrown when an error occurs during 
		 * fin.read() or fin.close() */
		catch(IOException ioe){
			System.out.println("I/O error");
			return -1;
		}
		
		return read;
	}

	public static void main(String[] argv){
		int ret  = 0;
		Lab1 lab = new Lab1();

		if(argv.length == 0){
			System.out.println("You did not supply enough number of parameters\n");
			System.out.println("Usage: java Lab1 <filename>");
			System.exit(-1);
		}

		File file = new File(argv[0]);
		ret = lab.readFile(file);

		if(ret > 0) 
			System.exit(0);
		else 
			System.exit(-1); 		
	}
}
