Forums Register Login

Servlet searching files of a directory

+Pie Number of slices to send: Send
I want to write a servlet that looks in a given directory and gets all the name of the files in a list, array or vector..
I know how to do it in a java application
File pathName = new File("DirName");
String[] fileNames = pathName.list();
But I don't know how to do it in a Servlet.
(I know how the servlets basic, and how to read file using a Servlet)
Thanks for your help
Luis Gallo
+Pie Number of slices to send: Send
A servlet's purpose in life is to generate a web page or other web document. So the question is: "What do you want to DO with the list, once it's generated?".
For example:
+Pie Number of slices to send: Send
 

Originally posted by Tim Holloway:
[B]A servlet's purpose in life is to generate a web page or other web document. So the question is: "What do you want to DO with the list, once it's generated?".
For example:
[/B]


Thank you for your reply. My question is how do I generate a list of files which appear in a directory. What API or classes should I use. I want to a directory which contatins a list of rdf files and make some query.
I know how to handle list, arrays or vectors, but I don't know how to get a list of files of a directory located in my server
(Apache)
If you can help me, I will appreciated a lot.
Thanks

+Pie Number of slices to send: Send
Check the docs on class java.io.File. You can use the list() method with a FileFilter or use listFiles() and filter them yourself.
File vDir = new File ("/home/httpd/xyz/mydir");
File[] contents = vDir.files();
for ( int i = 0; i < contents.length ; i++ ) {
....

Don't forget that Windows is insensitive to filename case, but Java ISN'T!
For more on file processing, check out the Big Moose "I/O and Streams" forum.
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2749 times.
Similar Threads
displaying file in jsp
Multiple excludes for ant copy task
I can list server text files, but cannot bring them up to display
Get a List of all files given a Directory\Volume Name
Prevent uploading executables
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:39:05.