Java NIO and NIO2 Overview
NIO2 interfaces bring some improvements to the
file/stream interfaces. Let’s see what has changed since the dark
ages of the inter-blago-tubes of the 90ies. Here is a brief history of the java I/O interfaces:
- The first one is Java I/O that is introduced in 1996 in the very first version of the JDK.
- The second, Java NIO has been added to the JDK in 2002, Java 4.
- The third, in 2011, in Java 7, Java NIO2 was introduced.
Over time, the following improvements have been added: Buffered readers/writers, bidirectional channels, off-heap buffering, proper support for charsets and asynchronous operations.
Probably the biggest difference between
java.nio is, however, that
java.nio can be used in non-blocking mode. This means that multiple streams can run in the same process/thread. This should, in theory, speed up performance because task/thread switching comes with some cost.