Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding the filenames of all the files in a directory

 
Aran King
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to find the filenames of all the files in a directory and store as Strings. Could l have some pointers as to what API's l would use to:
choose a directory
find the filenames.
Thanks Aran
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class API should have everything you need to do that, specifically returning an array of Strings containing the names of all the files in a directory. You can also test to see if it is a directory or a file.
Jason
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two specific methods for listing the files in a directory. They are both in the class File. list() and listFiles()
list() returns an array of Strings.
listFiles() returns an array of File objects.
There are also flavors of these two that incorporate filters for filenames.

------------------
Jason R. Kretzer
Software Engineer
 
Aran King
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guys thats great should have guessed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic