THE OCP EXAM TOPICS COVERED IN THIS CHAPTER INCLUDE THE FOLLOWING:
What can Java applications do outside the scope of managing objects and attributes in memory? How can they save data so that information is not lost every time the program is terminated? They use files, of course! You can design code that writes the current state of an application to a file every time the application is closed and then reloads the data when the application is executed the next time. In this manner, information is preserved between program executions.
This chapter focuses on using the
java.io API to interact with files and streams. We start by describing how files and directories are organized within a file system and show how to access them with the
java.io.File class. We then show how to read and write file data with the stream classes. Finally, we conclude this chapter by discussing ways of reading user input at runtime using the
In the next chapter, “NIO.2,” we will revisit the discussion of files and show how Java now provides more powerful techniques for managing files.
We begin this ...