Advertisement
chowdhury_riham

Java Code For Taking Input From File

Nov 3rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package readfile;
  7.  
  8. /**
  9.  *
  10.  * @author Riham
  11.  */
  12. import java.io.BufferedReader;
  13. import java.io.IOException;
  14. import java.io.FileReader;
  15. import java.util.ArrayList;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18. public class ReadFile1 {
  19.     public static void main(String args[]){
  20.         ArrayList<String> list=new ArrayList<String>();
  21.         BufferedReader br=null;
  22.         try {
  23.             br= new BufferedReader(new FileReader("C:\\Users\\User\\Desktop\\riham.txt"));
  24.             String i=null;
  25.             while((i=br.readLine())!=null){
  26.                 list.add(i);
  27.                
  28.             }
  29.             for(String x:list)System.out.println(x);
  30.              
  31.                
  32.         } catch(IOException e){
  33.             e.printStackTrace();
  34.         } finally{
  35.             try {
  36.                 br.close();
  37.  
  38.             } catch (IOException ex) {
  39.                 Logger.getLogger(ReadFile1.class.getName()).log(Level.SEVERE, null, ex);
  40.             }
  41.         }
  42.     }
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement