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 OverflowOracle
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.
Videos
06:54
How to READ FILES with Java in 8 minutes! 📖 - YouTube
08:32
How to WRITE FILES with Java in 8 minutes! ✍ - YouTube
How to Easily Read and Write to Files in Java (File I/O) - Java ...
07:20
Java File class 📁 - YouTube
08:18
Java File Input/Output - It's Way Easier Than You Think - YouTube
Java File Handling Explained | Streams, Buffers, Readers & Writers ...
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 · 中文 – 简体
Top answer 1 of 16
1153
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.
2 of 16
225
File folder = new File("/Users/you/folder/");
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) {
if (file.isFile()) {
System.out.println(file.getName());
}
}
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.
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.
Top answer 1 of 13
82
What you want is File.listFiles(FileNameFilter filter).
That will give you a list of the files in the directory you want that match a certain filter.
The code will look similar to:
Copy// your directory
File f = new File("C:\\example");
File[] matchingFiles = f.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith("temp") && name.endsWith("txt");
}
});
2 of 13
38
You can use a FilenameFilter, like so:
CopyFile dir = new File(directory);
File[] matches = dir.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.startsWith("temp") && name.endsWith(".txt");
}
});
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