I am reading a integer file using :
int len = (int)(new File(file).length());
FileInputStream fis = new FileInputStream(file);
byte buf[] = new byte[len];
fis.read(buf);
IntBuffer up = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
But, it creates two copies of file in memory, 1) Byte Array copy 2) IntBuffer copy.
Is it possible to use the code in such a way thus it will create only one copy in memory?
The javadocs and the implementation from Oracle that I’ve looked at indicate that what you are saying is not true. The javadocs say that:
The code shows that the
arraypassed intoByteBuffer.wrapis simply assigned as the internal array of theByteBuffer. TheByteBuffer.asIntBuffermethod simply shows the creation of anIntBufferthat uses theByteBuffer.