I have an array of longs
I want to write to disk. The most efficient disk I/O functions take in byte arrays, for example:
FileOutputStream.write(by
No, there is not a trivial way to convert from a long[]
to a byte[]
.
Your best option is likely to wrap your FileOutputStream
with a BufferedOutputStream
and then write out the individual byte
values for each long
(using bitwise operators).
Another option is to create a ByteBuffer
and put your long
values into the ByteBuffer
and then write that to a FileChannel
. This handles the endianness conversion for you, but makes the buffering more complicated.