Link to home
Start Free TrialLog in
Avatar of haneefnb
haneefnb

asked on

how to get file count in servlets or jsp


hi i want to know how to get no.of files in a directory.

of course i use this code
 int filecount=new File("images/ln/headings").listFiles().length;  
 to find the no.of files in the images/ln/headings directory. but i get always returns value 8 even the ./headings folder contains 10 or 20 files.

my doubt is this .class file is in app/WEB-INF/classes folder, but my targeted file is in app/images/ln/headings folder. so how can i use the above code to getting the file count in images/ln/headings folder..
Avatar of Mick Barry
Mick Barry
Flag of Australia image

its not where the class file is, it is where it is run from
use the absolute path to make sure you get the right directory
If its inside a webapp you can use the following to get the actual path of a file in the webapp

http://helpdesk.objects.com.au/java/how-to-get-the-path-of-a-file-in-a-web-application

Avatar of haneefnb
haneefnb

ASKER

thanks for u r reply

but what about the jsp code so please provide the jsp code for solving above problem

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> but what about the jsp code so please provide the jsp code for solving above problem

would be exactly the same, no need to change anything.


The solution was provided in the question
I provide the solution here, what problem did you have with it?

You wanted to know how to do this in jsp - i showed you at http:#24343499
was answered in my first post

its not where the class file is, it is where it is run from
use the absolute path to make sure you get the right directory
If its inside a webapp you can use the following to get the actual path of a file in the webapp

http://helpdesk.objects.com.au/java/how-to-get-the-path-of-a-file-in-a-web-application


What problem did you have with it?

which just copied what I already posted, nice work

:-)