Table of Content
How to list all files in a directory in java
Say we want get names of all the files under a directory and sub directories. Basically we need to able to look under each sub directory and if it has any files add to the result. This sounds like a problem that can be solved recursively.
In the following section we have two different methods doing the same thing. Example 1 we are creating a File object with given path and iterating over its contents. And if the content is file we are adding it to return list.
List the file names by calling listFiles on the root path, and then recursively calling it if we get any directory.
No comments :
Post a Comment
Please leave your message queries or suggetions.
Note: Only a member of this blog may post a comment.