Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is maximum file size that can be handled by the JVM?

Tags:

java

file-io

I wanted to know the maximum file size that can be read by Java code?

I wanted to handle file size of 100mb. is this possible?

If possible what are the JVM initial settings that I have to do?

Please recommend some best practice in handling file. like use ObjectInputStream,FilterInputStream etc.. use byte array to store file contents etc

like image 885
Dinesh Avatar asked Dec 27 '10 06:12

Dinesh


2 Answers

What's the biggest number you can write? That's the maximum size.

The total size of file is irrelevant if you read it in chunks; there's no rule in the world that would state that you have to read in your 100 megabyte file in one go, you can read it in, say, 10 megabyte blocks instead. What really matters is how you use that incoming data and whether you need to store the product of the raw data entirely (for example, if the data is a 3D model of a building, how do you internally need to represent it) or only the relevant parts (such as finding first ten matches to some clause from a huge text file).

Since there's a lot of possible ways to handle the data, there's no all-covering blanket answer to your question.

like image 135
Esko Avatar answered Oct 15 '22 20:10

Esko


The only maximum I know of is the reporting maximum of the length() - which is a Long. That length is 2^62 - 1, or very very large.

Java will not hold the entire file in memory at one time. If you want to hold part of the file in memory, you should use one of the "Buffered" classes (the name of the class starts with Buffered). These classes buffer part of the file for you, based on the buffer size you set.

The exact classes you should use depend on the data in the file. If you are more specific, we might be able to help you figure out which classes to use.

(One humble note: Seriously, 100mb? That's pretty small.)

like image 44
Jonathan B Avatar answered Oct 15 '22 21:10

Jonathan B