FileSystem - { printName( depth ); if( isDirectory( ) ) {...

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

View Full Document Right Arrow Icon
import java.io.*; public class FileSystem extends File { // Constructor public FileSystem( String name ) { super( name ); } // Output file name with indentation public void printName( int depth ) { for( int i = 0; i < depth; i++ ) System.out.print( "\t" ); System.out.println( getName( ) ); } // Public driver to list all files in directory public void listAll( ) { listAll( 0 ); } // Recursive method to list all files in directory private void listAll( int depth )
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { printName( depth ); if( isDirectory( ) ) { String [ ] entries = list( ); for( int i = 0; i &lt; entries.length; i++ ) { FileSystem child = new FileSystem( getPath( ) + separatorChar + entries[ i ] ); child.listAll( depth + 1 ); } } } // Simple main to list all files in current directory public static void main( String [ ] args ) { FileSystem f = new FileSystem( &quot;.&quot; ); f.listAll( ); } }...
View Full Document

Ask a homework question - tutors are online