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

Ads









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 install a .deb file via the command line?
how do i upload a file by using servlet or jsp?
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
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();
Javah -  Header File Generator
how do i solve this problem?
how do i solve this question?
Java2
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 compile the registration form?
How do I start learning Docker
How do I get started with Bootstrap

Ads