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 ...
Get Java™ Phrasebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.