• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting A File List From A Directory

 
Alan Jackson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, here is my problem. I'm trying to develop a small RMI application which will look in the folder "c:/alanistic" and produce an object array called "fileList" which will hold the names of all of the files in the directory. What I have been trying is:

File initialDir = new File("C:/comu303ass1");

public static void listFiles(File pInitialDir) {
File[] fileList = pInitialDir.listFiles();
for (int i = 0; i < files.length; i++) {
String fileName = fileList[i].getName();
}

Basically my app will act as a server, so when a client connects it will list all the files in the clients folder.

Any info is appreciated.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If what you want is just the names, why not use the list() method? The only reason I can think of to use listFiles() is so you can apply a FileFilter.
Bill
 
Michael Herrmann
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a little class and got it finished with the help of other form members that might help you(incl. recursively searching through subdirectories of subdirectories of subdirectories of...).
You can find it here

Regards,
Michael Herrmann
[ October 26, 2004: Message edited by: Michael Herrmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic