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

查看所有标签

Ajax Design Patterns

Ajax Design Patterns

Michael Mahemoff / O'Reilly Media / 2006-06-29 / USD 44.99

Ajax, or Asynchronous JavaScript and XML, exploded onto the scene in the spring of 2005 and remains the hottest story among web developers. With its rich combination of technologies, Ajax provides a s......一起来看看 《Ajax Design Patterns》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

SHA 加密
SHA 加密

SHA 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具