Path.of joins path segments without hard-coding the platform separator.

Path Join

PathJoin.java
import java.nio.file.Path;

public class PathJoin {
    public static void main(String[] args) {
        int lesson = ;
        String fileName = "lesson" + lesson + ".txt";
        Path path = Path.of("java", "files", fileName);

        System.out.println("parent=" + path.getParent());
        System.out.println("file=" + path.getFileName());
    }
}
import java.nio.file.Path;

public class PathJoin {
    public static void main(String[] args) {
        int lesson = ;
        String fileName = "lesson" + lesson + ".txt";
        Path path = Path.of("java", "files", fileName);

        System.out.println("parent=" + path.getParent());
        System.out.println("file=" + path.getFileName());
    }
}
import java.nio.file.Path;

public class PathJoin {
    public static void main(String[] args) {
        int lesson = ;
        String fileName = "lesson" + lesson + ".txt";
        Path path = Path.of("java", "files", fileName);

        System.out.println("parent=" + path.getParent());
        System.out.println("file=" + path.getFileName());
    }
}
path segment A path segment is one named part of a path, such as a directory name or file name.
joined path Joining segments lets Java choose the correct separator for the current system.