IO and NIO A fully fledged language can stand on its own without having to deal with external files, but this is only a theory. In fact, any language needs to exchange data with external files. A system that could not exchange anything with the outside world seemed useless. A closed single cell would not survive.

Java was born with SUPPORT for I/O, and a parallel set of apis, CALLED NIO, was added in Java version 1.4, all designed to improve performance. NIO2 came after Java 7, improving File operations and providing uniform support for all File systems.

I/O is the input/output of a computer and its peripheral devices. In terms of computer architecture, any process involving the transfer of data between a computer’s CPU or memory and other devices is called IO. This includes data streams and file systems, such as serial devices, byte streams, character streams, files, and networks, all of which are unified in the IO API. I/O support is to fetch data from a data source and write it to a data destination. Figure 9-1 shows the operating mode.

Figure 9-1 I/O running modes

Let’s start with the IO interface. Java supports I/O operations primarily through the java.io package, which helps users handle almost all computer input/output. I use the word “almost” here because the Java IO API package itself is incomplete and does not cover network socket, Internet, and GUI-related operations. But conceptually we can think of them as going together, but I’m going to focus on reading and writing files in the following examples, and I’m going to use a separate book for network IO.

File I/O interfaces can be categorized as follows.

Byte manipulation interfaces: InputStream and OutputStream. </