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?
Asked
Active
Viewed 165 times
0

Nore
- 111
- 2
- 4
- 20
-
this solution could be helpful http://stackoverflow.com/q/947730/778687 – tusar Mar 01 '12 at 09:11
-
how to do 'foreach directory' ? – Nore Mar 01 '12 at 09:19
1 Answers
1
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
}

Kuldeep Jain
- 8,409
- 8
- 48
- 73
-
is it possible to do foreach statement for those file lists? like `foreach file` – Nore Mar 01 '12 at 09:30