/////// 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); } } }