public static void main(String[] args) throws FileNotFoundException { if (args.length == 0) { // yeah, here's our scanner Scanner in = new Scanner(System.in); System.out.print("enter command (? for help)>"); String input = in.nextLine(); while (!(input.equals("q"))) { cmdProc(input); System.out.print("enter command (? for help)>"); input = in.nextLine(); } if (input.equals("q")) { System.out.println("quit"); in.close(); System.out.close(); } } // Oh, thanks for the args. Now we'll process your input file. else { File inpFile = new File(args[0]); // If for some reason it's not there or can't be read. if (!inpFile.exists() || !inpFile.canRead()) { System.out.println("Invalid input file!"); System.exit(1); } Scanner in = new Scanner(inpFile); try { while (in.hasNextLine()) { String temp = in.next(); cmdProc(temp); } }finally { in.close(); } } }