开发者社区> 问答> 正文

输出指定目录下的所有文件

输出指定目录下的所有文件

展开
收起
珍宝珠 2020-02-13 17:15:10 1414 0
1 条回答
写回答
取消 提交回答
  • class Main {
        public static void main(String[] args) {
            File dir = new File("C:");
            String[] children = dir.list();
            if (children == null) {
                System.out.println( "目录不存在或它不是一个目录");
            }
            else {
                for (int i=0; i< children.length; i++) {
                    String filename = children[i];
                    System.out.println(filename);
                }
            }
        }
    }
    
    

    以上代码运行输出结果为:

    build
    build.xml
    destnfile
    detnfile
    filename
    manifest.mf
    nbproject
    outfilename
    src
    srcfile
    test
    
    2020-02-13 17:15:33
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载