Read a file to multiple array byte[]
- by hankol
I have an encryption algorithm (AES) that accepts file converted to array byte and encrypt it.
Since I am going to process a very big size files, the JVM may go out of memory.
I am planing to read the files in multiple array byte. each containing some part of the file. Then I teratively feed the algorithm. Finally merge them to produce encrypted file.
So my question is: there any way to read a file part by part to multiple array byte?
I thought I can use the following to read the file to array byte:
IOUtils.toByteArray(InputStream input).
And then split the array into multiple bytes using:
Arrays.copyOfRange().
But I am afraid that the first code that reads file to byte will make the JVM to go out of memory.
any suggestion please ?
thanks