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 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 can i read a file from nth line onwards in java
how do i upload a file by using servlet or jsp?
how do i allow users to download a xls file in html?
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
How do I upgrade mysql?
How to Split a large XML file using java?
How can I do it? .click();
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 do i solve this problem?
how do i solve this question?
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 grab the url in php?
How do i do the coding for 'leaving a comment' in java
How to Read a File in Java
How do I compile the registration form?
how to read text file in jtable in netbeans7.0
How do I get started with Bootstrap
How do I get started with Bootstrap
Javah -  Header File Generator
How do I learn Spring Framework?

Ads