ListFiles - try { /* 7*/ theFile = new FileReader( fileName...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; public class ListFiles { public static void main( String [ ] args ) { /* 1*/ if( args.length == 0 ) /* 2*/ System.out.println( "No files specified" ); /* 3*/ for( int i = 0; i < args.length; i++ ) /* 4*/ listFile( args[ i ] ); } public static void listFile( String fileName ) { FileReader theFile; BufferedReader fileIn = null; String oneLine; /* 5*/ System.out.println( "FILE: " + fileName ); /* 6*/
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: try { /* 7*/ theFile = new FileReader( fileName ); /* 8*/ fileIn = new BufferedReader( theFile ); /* 9*/ while( ( oneLine = fileIn.readLine( ) ) != null ) /*10*/ System.out.println( oneLine ); } /*11*/ catch( Exception e ) /*12*/ { System.out.println( e ); } / // Close the stream /*13*/ try { /*14*/ if( fileIn != null ) /*15*/ fileIn.close( ); } /*16*/ catch( IOException e ) { } } }...
View Full Document

This document was uploaded on 06/13/2011.

Ask a homework question - tutors are online