Try With Resources Suppressed Exceptions

Auto-close resources with try-with-resources and handle suppressed exceptions.

JavaSecurity Boundaries

Code

snippet
import java.io.*;
import java.nio.file.*;

public class FileProcessor {
    public String readAndCopy(String src, String dst) throws IOException {
        try (var reader = Files.newBufferedReader(Path.of(src));
             var writer = Files.newBufferedWriter(Path.of(dst))) {
            String line;
            while ((line = reader.readLine()) != null) {
                writer.write(line);
                writer.newLine();
            }
            return "done";
        }
    }
}