The IistFiles ( ) Alternative Java Help

The listFiles ( ) Alternative

java 2  adds  variation to the list( ) method, called listfile( ), which you might find useful. The signatures for listfile( ) are shown here:

Filer[ ] listFiles( )
Filer[ ] listFiles(filenamefilter FFObj)
File[ ] listFiles(FileFilter FObj)

These methods return the file list .1S an array of File objects instead of strings. The first method returns all files, and the second returns those files that satisfy the specified FilenameFilter. Aside from returning an array of File objects, these two versions of listFiles( ) work like their equivalent list ) methods.

The third version of listFiles( ) returns those files with path names that satisfy the specified File Filter. File Filter defines only a single accommodating( ), which is called once for each . file in a list. Its general form is given here:

boolean accept(File path)

The accept( ) method returns true for files that should be included in the list (that is, those that match the path: argument), and false for those that should be excluded.

Creating Directories

Another two useful File utility methods are mkdir( ) and mkdirst( ). The mkdirt( ) method creates a directory, returning true on success and false on failure. Failure indicates that the path specified in the File object already exists, or that the directory cannot be, created because the entire path does not exist yet. To create a directory for which no path exists, use the mkdirt( ) method. It creates both a directory and all the parents of the directory.

  • Feel free to send us an inquiry, we will reply back in hours.


Posted on September 17, 2014 in Input/output: Exploring

Share the Story

About the Author

Back to Top
Share This