1. Introduction
The listFiles() method returns an array of File
objects that represent files and directories located on the specified path. The method is similar to list() but in this case we have handler to file instead of just a name in String.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- File
[]
- an array File objects. The array will be empty if the directory is empty.
Throws
- SecurityException - when we do not have access to the directory
3. Examples
3.1. Code that prints names of the files from /tmp/ttt
directory
The output:
4. Conclusion
In this article, we presented listFiles()
method that could be used to get an array of File objects representing files or directories on the specified path in the filesystem.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}