This code reads and prints the name of all the files and folders in a particular parent folder.
import java.io.File;
public class DirectoryReader {
public static void main(String[] args) {
File folder = new File("c:/");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment