Responsive Ad Area

Share This Post

test

Efficient ways to read and write integers in Java

I need manipulate a large file that cannot fit into memory.
My code involves a lot of read and write and my file only contains integers.
Right now I am using

DataInputStream in = new DataInputStream(new BufferedInputStream(
            new FileInputStream(inPath)));
int i = in.readInt();

and

DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
            new FileOutputStream(outPath)));
dos.writeInt(i);

for reading and writing integers.

However, having to constantly reading and writing leads to a really bad performance. After profiling my code, I found that most of time is spent on readInt() and writeInt(). How could improve the performance of reading and writing integers?


Efficient ways to read and write integers in Java
Efficient ways to read and write integers in Java
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar