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?