How to Read a Plain Text File in Java

0
151

This tutorial is all about How to Read a Plain Text File in Java.
In this post we will learn how to read data from a plain text file. There are multiple ways in Java about how to read data and write data from/in a text file. Also multiple third party party applications are present in the market which we can use while dealing with reading or writing operation.

Anyways , let us go through a simple program which demonstrate how to read data from a text file.

[java]

public class Manager{

public static void main( String [] args) {

File f=new File(“test.txt”)

//We are passing path of the file in the argument

FileReader fr=new FileReader(f);

BufferReader bin=new BufferrReader(fr);

String s1=bin.readLine(); // reading first line

while (s1!=null){

System.out.println(s1);

s1=bin.readLine();

// reading next line. Similarly this loop will read and print all the line

}

}

}

[/java]

Here readLine() method will read one line and move the cursor to the next line.

 

Readers might Read also:

 

 

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.