I need to read a file into an array of Bytes.The entire file needs to be read into the array. The problem is I am getting an OutOfMemory Error since the file size is too large.
You need to have far more free memory than the largest file you can have to use this approach. Given a machine with 24 GB costs less than £2K, this isn't as silly idea as it used to be. Actually the 2GB limit for a byte[] is more of a headache in some situations.
However, the usual way to read an InputStream is to read a block of say 8KB at a time. This way you only need to have far more than 8KB free.
BTW: You can use -mx1g instead of the option you are using.