How do I read a large file quickly in Java?

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









Related Tutorials/Questions & Answers:
How do I read a large file quickly in Java?
How do I read a variable from a file in shell script
Advertisements
How to read a large text file line by line in java?
How do I import a CSV file in R?
How do I compress a tar file in Linux
How do I compress a tar file in Linux
How do I compress a tar file in Linux
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
difference between java5 and java6 - Java Beginners
How do I install a .deb file via the command line?
how do i upload a file by using servlet or jsp?
how do i allow users to download a xls file in html?
How can i read a file from nth line onwards in java
How quickly can I learn Python?
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 to Split a large XML file using java?
How can I do it? .click();
How to upload a large excel file - JSP-Servlet
Javah -  Header File Generator
What changes I have to do in php.ini file for file uploading?
how do i solve this problem?
Java2
how do i solve this question?
How do i do the coding for 'leaving a comment' in java
How do I decompile Java class files?
How do I initialize a byte array in Java?
How do I compare strings in Java?
How do I choose a data science course?
How do I start learning Docker
How do I compile the registration form?
How do I get started with Bootstrap
How do I get started with Bootstrap
about java1
how do i grab the url in php?
how to read this xml file - XML
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I study big data?
How do I generate random number?
How do I start learning MongoDB?
How do I download urllib3 for python 2.7
How do I learn Python data science?
How do I start a data mining company?
How do I get a job in AI field?

Ads