1. Introduction
The list() method from Java IO API returns an array of pathnames that could contain files and directories. There is no guarantee that the name strings in the resulting array will appear in any specific order. The array will be empty if the directory is empty.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- String
[]
- array of the pathnames
Throws
- SecurityException - when we do not have access to the file or directory
3. Examples
3.1. The code snippet prints the names of folders and files in /tmp/ttt
directory
The output:
4. Conclusion
In this article, we presented list()
method that could be used to list the directory content. This method returns only names so to get File object from returned resources we should concatenate the root directory with that names.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}