views:

319

answers:

2

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
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
Try it and see what happens.
camickr
You'll want to change the file path.
thenoviceoof
I think this will print the directory names, and no filenames
Fortega
+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