hi, can any one help me . I want to read all the files in a folder through java. can any help me out???..
+1
A:
File folder = new File("/Users/you/folder/");
File[] listOfFiles = folder.listFiles();
for (File listOfFile : listOfFiles)
if (listOfFile.isDirectory())
System.out.println(listOfFile.getName());
davidrobles
2009-12-04 03:41:50
hi, will this show all the files that are present in the C drive or just the show the files that are in the particular folder.
Mrityunjay
2009-12-04 03:44:05
Try it and see what happens.
camickr
2009-12-04 03:45:14
You'll want to change the file path.
thenoviceoof
2009-12-04 05:15:26
I think this will print the directory names, and no filenames
Fortega
2009-12-04 10:17:24
+2
A:
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder) {
if (fileEntry.isDirectory() {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
rich
2009-12-04 11:21:06