Java I/O is so slow! What can I do about it?

It is, as far as we are aware, impossible to do fast I/O in Java without going through immense pains. It is, however, quite possible to get decent I/O speeds with only small efforts.

There are several things which will cause input in Java to be slow. One such thing is the Scanner class, which even though it is quite handy and easy to use, tends to be very slow even for such a simple task as reading a stream of integers.

Another very important thing is to always make sure that both input and output are buffered, by using e.g. the BufferedReader and BufferedOutputStream classes.

To simplify matters, we have written a small utility class for you, called This class provides both input and output functionality, and will be fast enough for any problem on Kattis.

$Id: javaio.php.en,v 1.3 2006/11/02 14:41:17 gkreitz Exp $