Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

manipulating directories

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which is supposed to go into a certain directory called year which has a subdirectory dayOfYear. The dayOfyear directory has data files which are named from the first day of the year to 365 or 366 depending on if it is a leap year. This servlet is supposed to get all the years from the year directory and get all the dayOfYears from the dayOfYear directory and print out a certain year and all of its days. How would I be able to access these directories and files, manipulate there names as strings, and output a year and all of its days as a string.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can manage directories using the java.io.File package.
Basically
f = new File(path);
File[] ls = f.listFiles();
Give you the list of the directories or files you have within the specified path.
ls[i].isDirectory(), well, it's quite obvious, tell you if it is a directory or a file..
and f.getName() give you the name
Take a look at java.io.File for further information
HTH
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ill check it out. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic