Modern file handling uses java.nio.file — Path for locations and the static Files utility class for operations. Task API Build a path Path.of("data", "users.csv") Read small file Files.readString(path), Files.readAllLines(path) Read large file lazily Files.lines(path) (Stream — close it!) or Files.newBufferedReader Write Files.writeString(path, text, StandardOpenOption.APPEND) Copy / move / delete Files.copy, Files.move, Files.deleteIfExists Directories Files.createDirectories, Files.list, Files.walk Metadata Files.size, Files.exists, Files.getLastModifiedTime Rules Always specify or rely on UTF-8 (the default since Java 18). Close streams with try-with-resources — Files.lines and Files.walk hold file handles. For very large files, stream line by line instead of loading everything into…
Key Takeaways
Use Path + Files (NIO.2) instead of legacy java.io.File.
readString/readAllLines for small files; lines()/BufferedReader for big ones.
Close Files.lines/list/walk streams with try-with-resources.