• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet searching files of a directory

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic