O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Listing a Directory

File directory = new File("users/tim");
											String[] result = directory.list();

We can also use the File class to list the contents of a directory. In this phrase, we use the list() method of the File class to get a String array containing all the files and subdirectories contained within the directory specified by the File object. If the directory does not exist, a null value is returned. The strings returned are filenames and simple directory names; they are not complete paths. Also, the results are not guaranteed to be in any defined order.

An alternate implementation of the list() method is also available. It accepts a java.io.FilenameFilter parameter and allows you to filter the files and directories returned in the list ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required