CodesJava

Easy learning with example program codes

read file content line by line java program

The readLine() method is used to get file content line by line. The readLine() returns one line at each iteration.

Example:

package com.codesjava;
 
import java.io.BufferedReader;
import java.io.FileReader;
 
public class ReadFile {
  public static void main(String args[]){
	 String fileName = "D:/Test files/file 3.txt";
	 BufferedReader br = null;
     String strLine = "";
     try {
         br = new BufferedReader( new FileReader(fileName));
         while( (strLine = br.readLine()) != null){
             System.out.println(strLine);
         }
     } catch (Exception e) {
         e.printStackTrace();
     } 
  }
}

Output:

Content file 3

Download this example.

Please follow and like us:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status