• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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..
0
haneefnb
Asked:
haneefnb
  • 5
  • 4
1 Solution
 
objectsCommented:
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

0
 
haneefnbAuthor Commented:
thanks for u r reply

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

0
 
CEHJCommented:
In JSP you could do the following but don't forget 'filecount' will count directories too


 int filecount=new File(application.getRealPath("images/ln/headings")).listFiles().length;  

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
> 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.


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

0
 
CEHJCommented:
You wanted to know how to do this in jsp - i showed you at http:#24343499
0
 
objectsCommented:
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?

0
 
objectsCommented:
which just copied what I already posted, nice work

0
 
CEHJCommented:
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now