Advertisement
chowdhury_riham

File Reader

Jan 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.FileReader;
  4. import java.util.ArrayList;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. public class ReadFile1 {
  8.     public static void main(String args[]){
  9.         ArrayList<String> list=new ArrayList<String>();
  10.         BufferedReader br=null;
  11.         try {
  12.             br= new BufferedReader(new FileReader("C:\\Users\\User\\Desktop\\riham.txt"));
  13.             String i=null;
  14.             while((i=br.readLine())!=null){
  15.                 list.add(i);
  16.                
  17.             }
  18.             for(String x:list)System.out.println(x);
  19.              
  20.                
  21.         } catch(IOException e){
  22.             e.printStackTrace();
  23.         } finally{
  24.             try {
  25.                 br.close();
  26.  
  27.             } catch (IOException ex) {
  28.                 Logger.getLogger(ReadFile1.class.getName()).log(Level.SEVERE, null, ex);
  29.             }
  30.         }
  31.     }
  32.    
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement