You're trying to create a (roughly) 4G array and it's too big to fit in the heap (one billion 4-byte integers).
Most likely, if you want to do it that way, you're going to need a 64-bit Java running on a 64-bit operating system (and possibly a large amount of physical memory for performance), and increasing the heap size to something much larger than the default (such as with java -Xmx6g
or something similar).
Or, if your algorithm is able to operate on the data in sections, that may be a better option.
So, if you're summing the items in the file, you can bring them in a thousand at a time to add them to a running total. Now that's not going to be easy if there's a lot of random access of all sorts of different integers but, in that case, you could possibly create the array on disk and use a caching/LRU interface to ensure you only load in what's needed at any given point.