Click to See Complete Forum and Search --> : java socket


mich
07-25-2008, 12:32 PM
hello,
I have a java server running and waiting for connections:
connection = server.accept();
From IE I type index.html to connect to server: how can I list in java the content of (eg "c:\server\bin\file1, file2, file3") server directory?
connection = server.accept();
if (request.filename == " index.html") printTheServerDirectotry....

THanks in advance,

Hack
07-31-2008, 02:44 PM
Do you simply need to list out all the names of the files in that folder?

If so, try something like thisimport java.io.File;

public class DirectoryReader {

public static void main(String[] args) {

File folder = new File("c:/server/bin");
File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}

}