I am writing a java program in which I have to write all integers to a file. To make it more efficient I just want to write int as only 4 bytes(which I think will be a binary file kind of thing, but I am not sure) and while reading back from the file I just want to read the integers directly(I do not want to read bytes and then convert them to integer).
Is there a way to do that.
I want to write millions of integers to the file I want the method to be fast and efficient.
I am new to this so please put up with me.
Use the
DataOutputStreamclass or aRandomAccessFile. Both provide methods for writing structured binary data, for example the “int as 4 bytes” you want.