Link to home
Start Free TrialLog in
Avatar of mookie13
mookie13Flag for United States of America

asked on

Read directory contents and output in in JSP page

Hi all,

I have several directories of static images and swf files. I want to build a JSP that reads the files, by file type, and renders the images/swf's on the output page. I'd also like to sort by date or file name. Make sense?

I can do this in Perl pretty easily like this:
$dirtoget="/home/www/site/";
opendir(IMD, $dirtoget) || die("Cannot open directory");

Then dump into an array:
@thefiles= readdir(IMD);

From there I could output however I wanted. Not sure how to do this in JSP. Help please... :)
Avatar of jmadda
jmadda

Try something like this...

String the_path = "/home/www/site/";
File theDir = new File(the_path);
String[] theDirectoryFiles = theFile.list();

for(int i=0; i<theDirectoryFiles.length; i++) {
    File theFile = new File(thePath + "//" + theDirectoryFiles[i]);
    //this file can then be printed out or whatever.
}

ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mookie13

ASKER

This is great!!! I was just now able to get back to this project. Appreciate your help!!