% java Concatenate Concatenate.java FileListEnumerator.java > Concatenate.out % more Concatenate.out /* * An example taken from Sun's online textbook "The Java Tutorial" * at URL http://java.sun.com/tutorial/index.html * */ import java.io.*; class Concatenate { public static void main( String[] args ) { // An Enumeration object: FileListEnumerator fileList = new FileListEnumerator( args ); try { SequenceInputStream in = new SequenceInputStream( fileList ); int c; while ( ( c = in.read() ) != -1 ) { System.out.write( c ); } in.close(); } catch ( IOException e ) { System.err.println( "Concatenate: " + e ); } } } // end class Concatenate import java.util.*; import java.io.*; class FileListEnumerator implements Enumeration { String[] listOfFiles; int current = 0; FileListEnumerator( String[] listOfFiles ) { this.listOfFiles = listOfFiles; } public boolean hasMoreElements() { return ( current < listOfFiles.length ); } public Object nextElement() { InputStream in = null; if ( !hasMoreElements() ) throw new NoSuchElementException( "No more files!" ); else { try { String nextElement = listOfFiles[ current++ ]; in = new FileInputStream( nextElement ); } catch ( FileNotFoundException e ) { System.out.println( "ListOfFiles: " + e ); } } return in; } } // end class FileListEnumerator