|
-
Apr 4th, 2001, 01:19 PM
#1
Thread Starter
Hyperactive Member
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-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Apr 6th, 2001, 11:47 AM
#2
Hyperactive Member
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--");
}
}
}
}
-
Apr 6th, 2001, 03:07 PM
#3
Thread Starter
Hyperactive Member
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-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
-
Apr 9th, 2001, 09:17 PM
#4
Thread Starter
Hyperactive Member
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-
"Blessed are we who can laugh at ourselves for we shall never cease to be amused"
- Unknown
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|