-
Does anybody happen to know how to retrieve the contents of a direcotry (like in a text field, print out all the files (their names) and subdirectories the current folder has)?
This would have to be done using an applet.
Any help would be greatly appreciated.
-JR-
-
Here is a quick way of doing it, do run this stuff in an applet are you meaning to get a directory listing on the client or the server?? If client I believe you will need to have the applet be signed.
Here is the code to do a directory listing, note: i just did this in an application, i didnt want to write a signed applet, but it isnt that hard.
I also put sorted the output by name of file, display the size of the file if not a sub directory, and display last modified date as formated.
import java.io.*;
import java.util.*;
import java.text.*;
public class ListOfFiles {
public static void main(String[] args) throws IOException {
File dir = new File(".");
File[] listing;
listing = dir.listFiles();
Arrays.sort(listing,new Comparator() {
public int compare(Object o1, Object o2) {
String s1 = o1.toString().toLowerCase();
String s2 = o2.toString().toLowerCase();
return s1.compareTo(s2);
}
});
for(int i=0;i<listing.length;i++){
SimpleDateFormat formatter = new SimpleDateFormat ("MMM-dd-yyyy ' ' hh:mm:ss");
Date temp = new Date(listing[i].lastModified());
String dateString = formatter.format(temp);
if(!listing[i].isDirectory()){
System.out.println(listing[i].getName()+"\t"+dateString+"\t"+listing[i].length());
}
else{
System.out.println(listing[i].getName()+"\t"+dateString+"\t--");
}
}
}
}
-
Thanks, I'll get back to this when I have the time to work on the project.
But thanks for the help! (By the way, the directory listing would have to be from the server)
-JR-
-
So how would I do one of these signed applets?
My java knowledge is somewhat limited, but I'll do my best to understand...
-JR-