• Post Reply Bookmark Topic Watch Topic
  • New Topic

list of File in a directory  RSS feed

 
hoang vo
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiousity if anyone can help me answer this:

File f = new File("c:\\newFolder");
//f is a directory called newFolder

String fileList[] = f.list();
//return the string arrays of the files in the folder of f



my question is:
in what order does the file being return are?
for example: newFolder has 5 file

09022005test1
09032005test2
08032005test3
..
.
etc

what orders are they return as?
by name? by creation? by modify? or maybe my size?

thnx for the answer
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API docs for the File class. The entry for the listFiles method specifically tells you about the order of the returned data.
 
hoang vo
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh i figure as much, they dont seem to appear in any particular format from my test either.

is there anyway to determine or to specify say: order by name or size?

I mean i can get the filename into an array of string and compare those with each other to determin the aphabetical order, or put it into an array of file and order the files using File.length() method.

But just want to know if there is any other ways to organize the returned String filename or File filename type to either aphabetical or size-wise.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.util.Arrays class can be used to sort arrays.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!