How can I do non-blocking I/O in Java?

John Mitchell

Using the standard, core Java I/O libraries, you can't. The basic idea there is to use separate threads. Note that there is a JSR in the works that will hopefully add both asynchronous and bulk I/O operations.

In the meantime, if you really do need to do non-blocking I/O, you can write it yourself using JNI or use/port a JNI-based wrapper like Mat Welsh's NBIO: Nonblocking I/O for Java package.

See the java.nio.channels package of Java 1.4 for support in 1.4.