- import java.io.File;
- //文件目录类
- public class MyDir {
- private String path;
- // 构造函数
- public MyDir(String path) {
- super ();
- this .path = path;
- }
- // 显示文件信息
- public void showAll() {
- File f = new File(path);
- if (f.exists() && f.isDirectory()) {
- System.out.println(f.getPath() + "/t<DIR>/t Start-------" );
- File[] files = f.listFiles(); // 返回抽象路径名数组
- for (File f1 : files) {
- if (f1.isDirectory()) {
- MyDir dir = new MyDir(f1.getPath());
- dir.showAll();
- } else if (f1.isFile()) {
- System.out.println(f1.getPath());
- }
- }
- System.out.println(f.getPath() + "/t<DIR>/t End-------/n" );
- }
- }
- public static void main(String[] args) {
- MyDir dir = new MyDir( "C://WINDOWS" );
- dir.showAll();
- }
- }
显示所有文件路径
最新推荐文章于 2022-02-23 15:02:25 发布