import java.nio.file.Path; import java.nio.file.Files; import java.io.BufferedReader; import java.io.IOException; import java.io.file.NoSuchFileException; public class Copy { public static void main(String[] args) { Path p = Path.of(args[0]); //try with resources closes the file for you try( BufferedReader br = Files.newBufferedReader(p); ) { String line = ""; while( (line = br.readLine()) != null) { System.out.println(line); } } catch(NoSuchFileException ex) { System.err.printf("File %s not found.\n", Path.toAbsolutePath(p)); } catch(IOException ex) { ex.printStackTrace(); } } }