Use:

public void listFilesForFolder(final File folder) {
    for (final File fileEntry : folder.listFiles()) {
        if (fileEntry.isDirectory()) {
            listFilesForFolder(fileEntry);
        } else {
            System.out.println(fileEntry.getName());
        }
    }
}

final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);

The Files.walk API is available from Java 8.

try (Stream<Path> paths = Files.walk(Paths.get("/home/you/Desktop"))) {
    paths
        .filter(Files::isRegularFile)
        .forEach(System.out::println);
} 

The example uses the try-with-resources pattern recommended in the API guide. It ensures that no matter circumstances, the stream will be closed.

Answer from rich on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Files.html
Files (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... This class consists exclusively of static methods that operate on files, directories, or other types of files.
🌐
W3Schools
w3schools.com › java › java_files.asp
Java Files
Java has several methods for creating, reading, updating, and deleting files.
🌐
GeeksforGeeks
geeksforgeeks.org › java › file-class-in-java
Java File Class - GeeksforGeeks
November 3, 2025 - The File class in Java is used to represent the path of a file or folder. It helps in creating, deleting, and checking details of files or directories, but not in reading or writing data.
🌐
Reddit
reddit.com › r/java › why is dealing with files so convoluted and unintiuitive in java?
Why is dealing with Files so convoluted and unintiuitive in Java? : r/java
May 31, 2020 - Regarding File and Path, both of these classes represent a file name. The file referenced by the object may not actually exist. File was the original object for this purpose. Path was added in I think Java 7.
🌐
GitHub
github.com › openjdk › jdk › blob › master › src › java.base › share › classes › java › nio › file › Files.java
jdk/src/java.base/share/classes/java/nio/file/Files.java at master · openjdk/jdk
JDK main-line development https://openjdk.org/projects/jdk - jdk/src/java.base/share/classes/java/nio/file/Files.java at master · openjdk/jdk
Author   openjdk
🌐
Android Developers
developer.android.com › api reference › file
File | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Find elsewhere
🌐
Medium
medium.com › @mzoughisalma93 › ️-java-file-class-more-than-just-files-d534fa1cfd04
🗂️ Java File Class: More Than Just Files | by Salma Mzoughi | Medium
November 30, 2025 - 🗂️ Java File Class: More Than Just Files Understanding How java.io.File Represents Both Files and Directories When learning Java I/O, developers often assume that the File class deals only …
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › package-summary.html
java.nio.file (Java Platform SE 8 )
April 21, 2026 - Defines interfaces and classes for the Java virtual machine to access files, file attributes, and file systems.
🌐
Baeldung
baeldung.com › home › java › java io › list files in a directory in java
List Files in a Directory in Java | Baeldung
January 8, 2024 - Another disadvantage of using listFiles() is that it reads the whole directory at once. Consequently, it can be problematic for folders with a large number of files. So let’s discuss an alternate way. Java 7 introduced an alternative to listFiles called DirectoryStream.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › nio › file › Files.html
Files (Java SE 11 & JDK 11 )
January 20, 2026 - Tests whether a file is readable. This method checks that a file exists and that this Java virtual machine has appropriate privileges that would allow it open the file for reading. Depending on the implementation, this method may require to read file permissions, access control lists, or other file attributes in order to check the effective access to the file.
🌐
Wikipedia
en.wikipedia.org › wiki › Java_class_file
Java class file - Wikipedia
May 30, 2026 - A Java class file is a file (with the .class filename extension) containing Java bytecode that can be executed on the Java Virtual Machine (JVM). A Java class file is usually produced by a Java compiler from Java programming language source files ( .java files) containing Java classes ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-files-nio-files-class
Java Files - java.nio.file.Files Class | DigitalOcean
August 4, 2022 - This class is used for basic file operations like create, read, write, copy and delete the files or directories of the file system. Before move ahead let’s have a look at the below terms first: Path: This is the interface that replaces java.io.File class as the representation of a file or a directory when we work in Java NIO.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › File.html
File (Java Platform SE 8 )
April 21, 2026 - Java™ Platform Standard Ed. 8 ... An abstract representation of file and directory pathnames.
🌐
Lifewire
lifewire.com › what-is-a-java-file-2622759
What's a JAVA File and How Do You Open One?
July 20, 2023 - A JAVA file is a Java source code file, a plain text file format that's essential to the process of building Java apps. Learn how to open JAVA files.
🌐
Medium
medium.com › javarevisited › reading-and-writing-files-in-java-a-comprehensive-guide-3fab0bfaf4cc
Reading and Writing Files in Java: A Comprehensive Guide | by Piyu Jain | Javarevisited | Medium
November 22, 2023 - It provides various classes for handling files, such as File, FileReader, FileWriter, FileInputStream, and FileOutputStream. The java.nio package is the newer file handling library, introduced in Java 1.4. It provides better performance and scalability than the java.io package.
🌐
Medium
beknazarsuranchiyev.medium.com › how-to-work-with-files-in-java-5f5d76012d63
How to work with Files in Java. In this article, I want to discuss in… | by Beknazar | Medium
April 24, 2022 - The first class we will take a look at is the File class. It represents files and directories in Java. While creating it we have to pass the file path(basically we need to tell which file or directory it should represent as a java object).
🌐
Baeldung
baeldung.com › home › java › java io › the java file class
The Java File Class | Baeldung
February 8, 2025 - In this tutorial, we’ll give an overview of the File class, which is part of the java.io API.
🌐
Sweet Home 3D
sweethome3d.com › download
Download - Sweet Home 3D
Read the README.TXT file included in this archive for instructions about installation process. ... This 7-zip archive contains Sweet Home 3D applications for 32-bit and 64-bit Windows, as well as 32-bit and 64-bit Linux, bundled with the Java environments required to execute them.
Published   February 10, 2026