Java 实例 - 输出指定目录下的所有文件

Java 教程 · 2019-02-11 08:14:14

以下实例演示了如何使用 File 类的 list 方法来输出指定目录下的所有文件:

Main.java 文件

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

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Data Structures and Algorithm Analysis in Java

Data Structures and Algorithm Analysis in Java

Mark A. Weiss / Pearson / 2006-3-3 / USD 143.00

As the speed and power of computers increases, so does the need for effective programming and algorithm analysis. By approaching these skills in tandem, Mark Allen Weiss teaches readers to develop wel......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试