Reputation: 111
I want to get all the file names in a JSP's server directory, and to do that i thought that it would be need some foreach
statement, how to do that?
Upvotes: 0
Views: 166
Reputation: 8598
Try this:
File file = new File(request.getRealPath(request.getServletPath()));
File[] fileList = file.getParentFile().listFiles();
You can iterate over this fileList
like this:
for (File file : fileList) {
// Do whatever you want
}
Upvotes: 1