Skip to content
Veltoryx Technologies
ProLesson 11.1Intermediate2 min readUpdated 30 October 2026

Files and Paths (NIO.2)

Work with files the modern way using Path and Files. Build paths, check, create, copy, move, delete and list files safely.

Modern Java code works with files through two classes from java.nio.file (Java 7+): Path, which describes a location, and Files, which does things with it. The old java.io.File class still works, but Path and Files are clearer and give better error messages.

01Building paths

Paths.java
import java.nio.file.Path;

public class Paths {
    public static void main(String[] args) {
        Path reports = Path.of("data", "reports", "2026");     // joins with the right separator
        Path file = reports.resolve("sales.csv");               // add a part
        System.out.println(file);
        System.out.println(file.getFileName());
        System.out.println(file.getParent());
        System.out.println(Path.of("data/./reports/../logs").normalize());
        System.out.println(file.isAbsolute());
    }
}
Expected output
data/reports/2026/sales.csv
sales.csv
data/reports/2026
data/logs
false

(On Windows, the separator prints as \.) A Path is just a description: creating one doesn't touch the disk.

Loading the rest of the lesson…