wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Finding the filenames of all the files in a directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finding the filenames of all the files in a directory" Watch "Finding the filenames of all the files in a directory" New topic
Author

Finding the filenames of all the files in a directory

Aran King
Greenhorn

Joined: Dec 10, 2001
Posts: 4
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

Joined: May 08, 2001
Posts: 1932
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

Joined: May 31, 2001
Posts: 280
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


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Aran King
Greenhorn

Joined: Dec 10, 2001
Posts: 4
Thanks Guys thats great should have guessed
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Finding the filenames of all the files in a directory
 
Similar Threads
Find n Replace word in set of files
Any DOS programmer here, I need your help.
Deleting multiple files at one go
regex needed to find all files with no extension
Seraching for files in directory