• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet searching files of a directory  RSS feed

 
luis gallo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
luis gallo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!