john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

fileBrowser

//requires CommandLineParams.java
import java.io.File;

public class FileBrowser
{
    File contents[];
    File start;

  public static void main( String args[] )
  {
    FileBrowser fb = new FileBrowser();
    System.out.println( "The root of your system: ");
    fb.contents = fb.getRoots( );
        fb.displayFileArrayElements( fb.contents );

        File f = new File( "/" );
        String listing[] = fb.getContents( f );
        int i = 0;
        for( i = 0; i < listing.length; i++ )
        {
            System.out.println( listing[i] );
        }


  } //end main


  private String[] getContents( File current )
  {
    String contents[] = null;
    try
     {      contents = current.list( );
     }
     catch( Exception e )
     {  e.printStackTrace();
     }
     return contents;
  }

  private File[] getRoots( )
  {
    File roots[] = null;
    try
     {
        roots = File.listRoots();           //available current FileSystem roots
     }
     catch( Exception e )
     {  e.printStackTrace();
     }
     return roots;
  }

  private void display( String args[] )
  {
    CommandLineParams cmdlineparams = new CommandLineParams( 1 , "version 0.1: java -jar FileBrowse.jar filename" );
    cmdlineparams.check( args , System.out );

        File f = new File( args[0] );

  }

  private void displayFileArrayElements( File a[] )
  {
    if( a != null )
    {
        for( int i = 0; i < a.length ; i++ )
        {   System.out.println( a[i] );
        }
    }
    else
    {   System.out.println( "Nothing to display." );
    }
  }

} //end class

  • « INCOMPLETE TrimFile
  • Perl file regex »

Published

Jan 16, 2012

Category

java

~138 words

Tags

  • filebrowser 2
  • java 252