Wednesday, August 7, 2019

Java Program to Read a Text File Line by Line

This tutorial explains how to read a text file line by line in java. This simple java code will explain these concepts of line by line file reading using java. Following source code help to search text.

Java Program to Read a Text File Line by Line

sample.txt
we are going to use below text file content using java code.
Simple Form Validation In Reactjs Example
Create a Dropdown Menu using ReactJS
Installing React Native on Windows Tutorial
Create Dropdown Menu In React Native
How To Customize Button In React Native
Facebook loading animation using CSS3
Facebook Style Chat Application with jQuery and CSS
Append Or Prepend HTML Using ReactJS
Create Ripple Animation Effect Using Css
Ripple Effect Animation On Button Click With CSS3

FileReadByline.java
package demo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileReadByline {

 public static void main(String[] args) throws IOException {

  // Creation of File Descriptor for input file
  File file = new File("sample.txt");

  // Creation of File Reader object
  FileReader fr = new FileReader(file);

  // Creation of BufferedReader object
  BufferedReader br = new BufferedReader(fr);

  String s = null;

  // Reading the content line by line
  while ((s = br.readLine()) != null) {
   System.out.println(s);

  }
  
  fr.close();

 }

}

output :
-----------------

Java Program to Read a Text File Line by Line



No comments:

Post a Comment