How to Read a file line by line using BufferedReader?

How to Read a file line by line using BufferedReader?

Hello Java developers.

I have studied java very well in last few months. A work is assigned to me in my company. Here I have many big text files. I have to read these files efficiently and the extract the business data and insert into database.

My problem is to find the best way to read the file in Java. I just searched the google and found that BufferedReader can be used.

So, help me and let's know How to Read a file line by line using BufferedReader, efficiently and using less memory.

Thanks

View Answers

February 9, 2013 at 12:12 AM

Hi,

You are right you can use the BufferedReader class for reading the big files which many range in many GB's is size.

It's not possible to read the whole file in memory. So, it's better to use the BufferedReader class.

The BufferedReader is present in java.io package. You can import

java.io.BufferedReader

in your program and use the class for reading the file line by line.

You can use the readLine() method of the class to read one line at a time very efficiently.

View the detailed example and code at Java Read File Line by Line - Java Tutorial page.

Thanks









Related Tutorials/Questions & Answers:
How to Read a file line by line using BufferedReader?
how to read file line by line using filereader in java
Advertisements
How to read big file line by line in java?
nio read file line by line
How to Read file line by line in Java program
Java Read File Line by Line - Java Tutorial
Java read file line by line
How to read a large text file line by line in java?
How to read a line from a doc file
Read Specific Line from file Using Java
objective c read file line by line
java - read file line by line in Java
How to read a file line by line?
Java read file line by line - Java Tutorial
Java - How to read a string line per line
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
How can i read a file from nth line onwards in java
Read file from the Nth line
How to write file by line in Java
how to write to file at the end of the line
Java file line reader
Read file line by line in Java 8
Line by Line reading from a file using Scanner Class
Java write to file line by line
How to write file text In New Line
How To Read Integer From Command Line In Java
How to read file in java
Java Write To File By Line
Line Graph using JFreeChart
Line Graph using JFreeChart
Line Graph using JFreeChart
Example code of reading file line by line in Java with Apache Commons IO library
how to read file using InputStreamReader in java
Java file new line
how to read and write an xml file using java
How can I execute a PHP script using command line?
How to Check Markup in PHP File from Command Line
How to extract a specific line from a text file? - IoC
How can i draw a line using java swings
How can i draw a line using java swings
How do I install a .deb file via the command line?
HOW TO PARSE FILE WITH SEVERAL DELIMITERS AND LINE FEEDERS - Java Beginners
line number in a file of entered string
Write Text To File In New Line.
Java read file
How To Read String From Command Line In Java
Read text file in PySpark
How to read the data in text file seperated by by ',' in java using IO Operations
Java Write To File End Of Line
execute a PHP script using command line

Ads