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://codercto.com/courses/l/12.html

查看所有标签

Eric Meyer on CSS

Eric Meyer on CSS

Eric Meyer / New Riders Press / 2002-7-8 / USD 55.00

There are several other books on the market that serve as in-depth technical guides or reference books for CSS. None, however, take a more hands-on approach and use practical examples to teach readers......一起来看看 《Eric Meyer on CSS》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

URL 编码/解码
URL 编码/解码

URL 编码/解码