以下实例演示了使用 file 类的 listroots() 方法来输出系统所有根目录:
/*
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());
}
}
}
以上代码运行输出结果为:
系统所有根目录:
c:\
d:\
e:\
f:\
g:\
h:\
以上就是java 实例 - 查看系统根目录的内容。
