import java.io.*; import java.util.*; /** * Simple program to show how to handle an optional input file argument. * * Read lines from either the input file named as a program argument or * from standard input if no file name is present. Copy the contents of * the file to standard output. */ class OptionalFile { public static void main(String[] args) throws FileNotFoundException { InputStream in; if (args.length == 0) { in = System.in; } else { in = new FileInputStream(args[0]); } Scanner s = new Scanner(in); while (s.hasNextLine()) { System.out.println(s.nextLine()); } } }