Solved

how to get file count in servlets or jsp

Posted on 2009-05-09
10
274 Views
Last Modified: 2013-11-24

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
Comment
Question by:haneefnb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24342743
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
 

Author Comment

by:haneefnb
ID: 24343067
thanks for u r reply

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

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24343499
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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 92

Expert Comment

by:objects
ID: 24346027
> 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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24421521
The solution was provided in the question
0
 
LVL 92

Expert Comment

by:objects
ID: 24421556
I provide the solution here, what problem did you have with it?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24421579
You wanted to know how to do this in jsp - i showed you at http:#24343499
0
 
LVL 92

Expert Comment

by:objects
ID: 24421653
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
 
LVL 92

Expert Comment

by:objects
ID: 24421742
which just copied what I already posted, nice work

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24421957
:-)
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question