I was facing below exception when I was making use of Files.readAllBytes from java 7 which then got solved by using FileUtils.readFileToByteArray from apache. I took that decision by going through few answers in stackoverflow. I tried understanding by going through the code to know the main difference which can solve this issue but in vain. I just want to know what difference in these two that solved this exception.
java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:658)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:123)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:174)
at sun.nio.ch.IOUtil.read(IOUtil.java:196)
at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:143)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
at java.nio.file.Files.read(Files.java:2903)
at java.nio.file.Files.readAllBytes(Files.java:2953)