This could be done in this way:
File fol = new File("D:/folder");
File[] listFiles= fol.listFiles();
for (int i = 0; i < listFiles.length; i++) {
if (listFiles[i].isFile()) {
System.out.println("File " + listFiles[i].getName());
} else if (listFiles[i].isDirectory()) {
System.out.println("Directory " + listFiles[i].getName());
}
}