file listRoots Example
file class listRoots example. This example shows you how to use listRoots method.
File class listRoots example.method generates root directory of files or directories.here for every file a single root directory this '/' is displayed every time. this is because in UNIX there is single root directory '/' is located for all file types, whereas in windows platform every file has unique root directory.each file system has a root directory from which all files in the file system can be reached.
Here is the code:-
/**
* @Program uses listRoots method to list root directory of
* the abstract pathname file or directory.
* ListRoots.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.File;
import java.io.IOException;
public class ListRoots {
public static void main(String args[]) throws IOException {
File bond007 = new File("/home/baadshah/Desktop");
File bond0007 = new File("/home/baadshah");
File bond00007 = new File("/home");
File array0[] = bond007.listRoots(),
array1[] = bond0007.listRoots(),
array2[] = bond00007.listRoots();
int i;
System.out.println("list of root directories in UNIX: ");
for (i = 0; i < array0.length; i++) {
System.out.println(array0[i]);
}
for (i = 0; i < array1.length; i++) {
System.out.println(array1[i]);
}
for (i = 0; i < array2.length; i++) {
System.out.println(array1[i]);
}
}
} |
Output of the program:-
list of root directories in UNIX:
/
/
/ |
|