When calling .length() on a file object, files over 2 GB return an incorrect value.
This is happening in a web application running in a tomcat container.
For example, a file that windows reports as 2,083,344,714 bytes is coming back as 1887961088 from java.
Here are the environmental details:
- jdk 1.6.0_24(64 bit)
- Java JotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)
- Tomcat 6.0.29
- Windows Server 2008 r2
So I immediately suspected something to do with a 32bit VM, but everything appears to be running in 64 bit. I’m totally stumped, any help would be greatly appreciated, if only help developing some tests to see if the problem is related to something running in 32 mode somehow..
EDIT:
To answer some comments:
When I run a really simple test case using the same JVM (just output file.length) I get the correct value: 2,083,344,714.
I am pretty confident that this should work, I am just feeling like something about my tomcat configuration/ java configuration/ application is giving me a hard time. The fact that it is affecting only files over a certain size really makes it seem like an issue with 32 bit vs 64 bit, but as far as I can tell everything is 64 bit.
EDIT 2: Starting to suspect this is pretty much not possible, and I might have an issue with a thread taking the length of a file before it has been copied completely. I’ll post here when I figure it out, if anyone cares 🙂
Seems to work fine for me…
pagefile.sys on Windows 7 x64, reported by DOS as 8446545920 bytes
Java 7.0_02 x32
8446545920 / 7.87 gb
Java 1.6_30 x32
8446545920 / 7.87 gb