Here is a Java Program for Using directories.
Output of Above Java Program
Directory of /java
COPYRIGHT is a directory
DevelopmentTutorial.com is a directory
Index.php is a file
Language-Tutorial is a directory
import java.io.File; class DirList { public static void main(String args[]) { String dirname = "/java"; File f1 = new File(dirname); if (f1.isDirectory()) { System.out.println("Directory of " + dirname); String s[] = f1.list(); for (int i=0; i < s.length; i++) { File f = new File(dirname + "/" + s[i]); if (f.isDirectory()) { System.out.println(s[i] + " is a directory"); } else { System.out.println(s[i] + " is a file"); } } } else { System.out.println(dirname + " is not a directory"); } } }
Output of Above Java Program
Directory of /java
COPYRIGHT is a directory
DevelopmentTutorial.com is a directory
Index.php is a file
Language-Tutorial is a directory