/////// Lowercase.java /////// // Example for text-file I/O import java.io.*; class Lowercase { public static void doio(InputStream i, OutputStream o) { int c; InputStreamReader in = new InputStreamReader(i); OutputStreamWriter out = new OutputStreamWriter(o); try { while ( (c = in.read()) >= 0 ) { c = Character.toLowerCase( (char) c); out.write(c); } out.flush(); } catch( IOException e ) { System.err.println("doio: I/O Problem"); System.err.println(e.getMessage()); System.exit(1); } } public static void main (String args[]) { int argn = args.length; if ( argn == 0 ) // use standard I/O doio(System.in, System.out); else if ( argn == 2 ) // use files given { try { FileInputStream infile = new FileInputStream(args[0]); FileOutputStream ofile = new FileOutputStream(args[1]); doio(infile, ofile); infile.close(); ofile.close(); } catch ( FileNotFoundException e ) { System.err.println( "Can't open input file " + args[0]); System.err.println(e.getMessage()); System.exit(1); } catch ( IOException e ) { System.err.println( "Can't open output file " + args[1]); System.err.println(e.getMessage()); System.exit(1); } } else // error { System.err.println("Usage: Lowercase infile outfile"); System.exit(1); } } }