Re: How to (efficiently) write an int array into a file ?
Alexandre Ferrieux wrote:
Hi,
What's the fastest way of writing a large array of ints into a file ?
There is no .getBytes() in int[], so OutputStream.write() is no
option.
Also, DataOutputStream allows to write ints, but one by one...
The closest I've come to a true cast is ByteBuffer.asIntBuffer(). But
starting from an int[], one still needs to use put() to populate the
Int/ByteBuffer with the data from the array.
How do we accomplish this simple task of a direct write to disk of a
big (packed) array of ints, in native byte order ?
TIA,
-Alex
You can always buffer the DataOutputStream or use ObjectOutputStream to
write the whole array. The thing that could cause you some problem is
the native byte order bit. Java uses big endian (I think) regardless of
platform. So you may have to convert to bytes your self and then write
it. Either way, the disk I/O is going to be the slow part.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access