I wanna read huge file(more then GB) and convert that as byte array in order to store the file dB.
The problem i am facing is when i convert file to byte array or reading the file i am getting Java heap memory run-time exception
I want to know what is the best way to read file and convert to byte array without being using more memory
I have googled i found that IOUtils provide better performance but i tried that it dint help me. I using java 8
private void readFile() throws IOException {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("C:\test.mp4")
byte[] bytes = IOUtils.toByteArray(fileInputStream);
Base64 codec = new Base64();
byte[] decoded = codec.encode(bytes);
fileInputStream.close();
}
Can you please help to convert that file to byte array with best approach?