Is there a way in Java to write a large array of, say, integers to disk? I am doing this on Android and have not found a method that comes close to the very native C code.
The resulting file should not be portable to different machines with different views, so logically just a voluminous record of basic bytes should be sufficient. But I do not know how to do this effectively with Java.
I tried searching the net and tested the following:
- Serialization is very slow, as expected.
- Using NIO is still slow - Android tracing shows operations one by one:
Thanks in advance
NIO Code:
int[] array = new array[10000000];
...
raf = new RandomAccessFile(ti.testFileName, "rw");
chan = raf.getChannel();
MappedByteBuffer out = chan.map(FileChannel.MapMode.READ_WRITE, 0, array.length*4);
ib = out.asIntBuffer();
ib.put(array);
out.force();
raf.close();