Advertisement
romancha

FileSecond

Mar 14th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. public class PrintFile {
  6.     public static void main(String[] args) {
  7.         if(args.length > 0) {
  8.             try(BufferedReader reader = new BufferedReader(new FileReader(args[0]))) {
  9.                 System.out.println(args[0] + ":\n");
  10.                 String currentLine;
  11.                 while ((currentLine = reader.readLine()) != null) {
  12.                     System.out.println(currentLine);
  13.                 }
  14.             } catch (IOException e) {
  15.                 System.out.println("Incorrect filename!");
  16.                 e.printStackTrace();
  17.             }
  18.         } else {
  19.             System.out.println("There is no args!");
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement