Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to Read a file line by line using BufferedReader?

Have Programming Question? Ask it here!
 
 
 


Java Coder
How to Read a file line by line using BufferedReader?
1 Answer(s)      a year and 6 months ago
Posted in : Java Beginners


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


Advertisement
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:
Advertisements
Advertisements
 

 

 

DMCA.com