Unit 14 · lesson

Path and Files Belong to the Full JDK Lane

The official Java Playground is excellent for language work, but a browser snippet environment is not your local operating system filesystem.

Authentic file evidence belongs in an approved Java 25 JDK environment.

Full-JDK lane

A simple read-all-lines workflow:

import java.nio.file.Files;
import java.nio.file.Path;
import java.io.IOException;
import java.util.List;

class FileDemo {
    public static void main(String[] args) throws IOException {
        Path path = Path.of("data", "matches.csv");
        List<String> lines = Files.readAllLines(path);

        for (String line : lines) {
            System.out.println(line);
        }
    }
}

This lesson deliberately uses a conventional explicit class and public static void main so you see mainstream project structure after the compact-source on-ramp.

Path is not file contents

Path represents a location in a filesystem model.

Path path = Path.of("data", "matches.csv");

does not prove the file exists or has been read.

Files.readAllLines(path) performs an I/O operation that can fail because of environment state such as missing path, permissions, or other I/O conditions.

Keep parsing independent

If parseLine(String line) already works from the browser core, the file layer can remain thin:

Files.readAllLines
       |
       v
List<String>
       |
       v
parseLine for each line
       |
       v
List<MatchRecord>

Now a filesystem defect and a data-format defect are easier to separate.

Relative paths depend on working context

Path.of("data", "matches.csv") is relative. What it resolves against depends on the process working directory.

If a file is "right there" but Java cannot find it, inspect the path your process is actually using instead of copying the file randomly into multiple folders.

Useful evidence can include:

System.out.println(path.toAbsolutePath());

Browser equivalent

If you do not have the full-JDK lane, do not fake a screenshot of Files.readAllLines.

Use the supplied List<String> records from Lesson 1 and demonstrate parsing, validation, and error reporting. Mark filesystem execution as not performed.

That is more honest evidence than pretending a browser string is a real file.

Full-JDK evidence

If you have the environment, create a tiny local text file with fictional non-sensitive data and record:

  • relative path;
  • absolute path printed by the program;
  • line count;
  • first/last line;
  • one missing-file failure;
  • successful restoration after correcting only the path/file condition.

Never use real student records or school operational files for this exercise.