开发者

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

开发者 https://www.devze.com 2023-02-01 12:23 出处:网络
I wanted to know the maximum file size that can be read by Java c开发者_C百科ode? I wanted to handle file size of 100mb. is this possible?

I wanted to know the maximum file size that can be read by Java c开发者_C百科ode?

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


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.


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.)


There is not any max file size that can be read theoretically but I think it is Integer.MAX_VALUE because you can't initialize charBuffer's size bigger than Integer.MAX_VALUE

char[] buffer = new char[/* int size */];
char[] buffer = new char[Integer.MAX_VALUE]; // maximum char buffer

BufferedReader b = new BufferedReader(new FileReader( new File("filename")));
b.read(buffer);


There is no specific maximum file size supported by Java, it all depends on what OS you're running on. 100 megabytes wouldn't be too much of a problem, even on a 32-bit OS.

You didn't say whether you wanted to read the entire file into memory at once. You may find that you only need to process the file a part at a time. For example, a text file might be processed a line at a time, so there would be no need to load the whole file. Just read a line at a time and process each one.

If you want to read the whole file into one block of memory, then you may need to change the default heap size allocate for your JVM. Many JVMs have a default of 128 MB, which probably isn't enough to load your entire file and still have enough room to do other useful things. Check the documentation for your JVM to find out how to increase the heap size allocation.


As long as you have more than 100 MB free you should be able to load the entire file into memory at once, though you probably won't need to.

BTW: In term of what letters mean

M = Mega or 1 million for disk or 1024^2 for memory.
B = Bytes (8-bits)
b = bit e.g. 100 Mb/s
m = milli e.g. mS - milli-seconds.

A 100 milli-bits only makes sense for compressed data, but I assumed this is not what you are talking about.

0

精彩评论

暂无评论...
验证码 换一张
取 消