Java 实例 - 在指定目录中查找文件

Java 教程 · 2019-02-11 08:27:12

以下实例演示了在 C 盘中查找以字母 'b' 开头的所有文件:

Main.java 文件

import java.io.*; class Main { public static void main(String[] args) { File dir = new File("C:"); FilenameFilter filter = new FilenameFilter() { public boolean accept (File dir, String name) { return name.startsWith("b"); } }; String[] children = dir.list(filter); 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

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

查看所有标签

Artificial Intelligence

Artificial Intelligence

Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00

The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换