I'm looking for a way to read a large number of ints from a DataInputStream and load them into an array. I know exactly how many int
s I need to read, but it'd be nice if there was a cleaner way than to simply iterate.
There is already a way to do this with a byte array, just by using the DataInputStream#read(byte[])
method, but there is no equivalent for int[]
. I could obviously read the data into a byte array by creating a byte array with the length multiplied by four, but I really need the data in int
s.
The way I see it, there are three possibilities I could use:
- Somehow load the data directly into an
int[]
. - Somehow convert a
byte[]
into anint[]
. - Iterate through the array and just use
readInt()
.
While the first two solutions are much preferred, I currently don't know of a way to do either. Is there any simple way to do this without iteration?