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

Java 教程 · 2019-02-11 06:56:36

以下实例演示了使用 File 类的 dir.list() 方法在指定目录中查找所有文件列表:

Main.java 文件

import java.io.File; public class Main { public static void main(String[] argv) throws Exception { File dir = new File("../java"); 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); } } } }

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

Car.class
FileUtil.class
FileUtil.java
HelloWorld.class
HelloWorld.java
HelloWorldDebug.class
HelloWorldDebug.java
……

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

查看所有标签

Programming Concurrency on the JVM

Programming Concurrency on the JVM

Venkat Subramaniam / The Pragmatic Bookshelf / 2011-6-1 / USD 35.00

Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show you all these con......一起来看看 《Programming Concurrency on the JVM》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

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

URL 编码/解码

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

UNIX 时间戳转换