Chapter 9 NIO.2

THE OCP EXAM TOPICS COVERED IN THIS CHAPTER INCLUDE THE FOLLOWING:

  • ✓  Java File I/O (NIO.2)
    • Use Path interface to operate on file and directory paths
    • Use Files class to check, read, delete, copy, move, manage metadata of a file or directory
    • Use Stream API with NIO.2

images

In Chapter 8, “IO,” we presented the java.io API and discussed how to use it to interact with files. In this chapter, we focus on the java.nio version 2 API, or NIO.2 for short, to interact with files. NIO.2 is an acronym that stands for the second version of the Non-blocking Input/Output API, and it is sometimes referred to as the “New I/O.”

In this chapter, we will show how the NIO.2 API allows us to do a lot more with files and directories than the original java.io API. We will also show you how to read and modify the attributes of a file. We will conclude the chapter by introducing new NIO.2 methods that were added in Java 8, which rely on streams to perform complex operations with only a single line of code.

Get OCP Oracle® Certified Professional Java® SE 8 Programmer II now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.