• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to copy the list of files in a directory to an array?  RSS feed

 
Jon Hedge
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to get the list of the files in a directory using the code below but it seems to have something missing (there is no output printed).

Thanks in advance for your help.

 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Jon Hedge wrote:(there is no output printed)
Probably that is not quite true. I suspect you see something similar to [Ljava.io.File;@6d06d69c.

Since you got an array, you need to iterate it through one of the loops, for example enhanced for loop and print out values. i.e.:

Wondering about [Ljava.io.File;@6d06d69c? it is a class name and the hashcode of the object in hexadecimal notation, because arrays does not override toString method.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The other possibility: there is no C:\Test folder on your computer, and therefore the isDirectory() method returns false.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!