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
How to read a large text file line by line in java?
Java read file line by line
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 - How to read a string line per line
How can i read a file from nth line onwards in java
Java read file line by line - Java Tutorial
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
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
Example code of reading file line by line in Java with Apache Commons IO library
Line Graph using JFreeChart
Line Graph using JFreeChart
Line Graph using JFreeChart
how to read file using InputStreamReader in java
how to read and write an xml file using java
How to Check Markup in PHP File from Command Line
How to extract a specific line from a text file? - IoC
How do I install a .deb file via the command line?
How can I execute a PHP script using command line?
HOW TO PARSE FILE WITH SEVERAL DELIMITERS AND LINE FEEDERS - Java Beginners
Java file new line
How can i draw a line using java swings
How can i draw a line using java swings
line number in a file of entered string
Write Text To File In New Line.
How To Read String From Command Line In Java
Java read file
How to read the data in text file seperated by by ',' in java using IO Operations
Read text file in PySpark
Java Write To File End Of Line
writing a text into text file at particular line number

Ads