The following example demonstrates using the listRoots() method of the File class to output all root directories of the system:
/* author by w3cschool.cc Main.java */ import java.io.*; class Main{ public static void main(String[] args){ File[] roots = File.listRoots(); System.out.println("系统所有根目录:"); for (int i=0; i < roots.length; i++) { System.out.println(roots[i].toString()); } } }
The output result of running the above code is:
系统所有根目录: C:\ D:\ E:\ F:\ G:\ H:\
The above is the Java example - View the contents of the system root directory. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!