Advertisement
apl-mhd

File read in java

Jun 16th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package com.company;
  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.Paths;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.  
  11.         FileReader fr = null;
  12.         BufferedReader br = null;
  13.         try {
  14.             fr = new FileReader("input.txt");
  15.             br = new BufferedReader(fr);
  16.  
  17.             String crLine;
  18.             while((crLine = br.readLine()) != null){
  19.                 System.out.println(crLine);
  20.             }
  21.  
  22.             //br = new BufferedReader(new FileReader("input.txt"));
  23.         }
  24.         catch (IOException x) {
  25.             System.out.println("File not found");
  26.         }
  27.         finally {
  28.             try {
  29.                 if (br != null)
  30.                     br.close();
  31.                 if (fr != null)
  32.                     fr.close();
  33.             } catch (IOException e) { }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement