import java.nio.file.Path; import java.nio.file.Files; import java.io.BufferedReader; import java.io.IOException; import java.io.FileNotFoundException; public class Cat { 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(FileNotFoundException ex) { System.err.printf("File %s not found.\n", Files.toAbsolutePath(p)); } catch(IOException ex) { ex.printStackTrace(); } } }