How do I read a large file quickly in Java?

Ads
 

How do I read a large file quickly in Java?

Hi,

I my project I have to read vendor feed which comes in text file. Size of the file is usually in 1-2 GB in size. What is the best way to read the file efficiently?

How do I read a large file quickly in Java?

Thanks

View Answers

April 5, 2017 at 1:24 PM

Hi,

You can't read the whole file in memory and process it line by line. The memory size is a constraint for the computer and even for servers. So, only one method is possible and it is of reading the file line by line.

In Java you can use the BufferedReader class for reading the file line by line. Reading file one line at a time using the BufferedReader class uses very less memory and the program works very fast.

Check the tutorial: Java Read File Line by Line.

The Scanner class can also be used for reading the file line by line. Check this tutorial: Line by Line reading from a file using Scanner Class.

Thanks

Ads









Related Tutorials/Questions & Answers:
How do I read a large file quickly in Java?
How to read a large text file line by line in java?
Advertisements
How do I import a CSV file in R?
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
how do i upload a file by using servlet or jsp?
How can i read a file from nth line onwards in java
difference between java5 and java6 - Java Beginners
how do i allow users to download a xls file in html?
How to Split a large XML file using java?
How to upload a large excel file - JSP-Servlet
How do I upgrade mysql?
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file
How can I do it? .click();
Javah -  Header File Generator
how do i solve this problem?
how do i solve this question?
Java2
How to read an eml file? - Java Beginners
How do I compare strings in Java?
How do I decompile Java class files?
How do I initialize a byte array in Java?
how to read this xml file - XML
What changes I have to do in php.ini file for file uploading?
How do i do the coding for 'leaving a comment' in java
how do i grab the url in php?
How do I compile the registration form?
How to Read a File in Java
How do I learn Spring Framework?
How do I learn Spring Framework?

Ads