[JAVA] 显示目录及子目录所有内容

    public static void PathList(File file)
    {
        String[] items = file.list();
        assert items != null;
        for (String s: items)
        {
            String path = file.getParent() + "\\" + s;
            File file1 = new File(path);
            if (file1.isDirectory())
            {
                PathList(file1);
            }
            else
            {
                System.out.println(path);
            }
        }
    }

    public static void main(String[] args) {
        File file = new File("E:\\个人\\");
        if (file.isDirectory()) {
            PathList(file);
        }
    }

你可能感兴趣的:(java,开发语言)