Working with Files
摘要
One of the most important functions in software is information organizing and storage, with the goal of using it and sharing it. The traditional (and fading) way of organizing and storing information is to write it on paper and store the paper in organized file cabinets from which it can be retrieved when needed. Software applications do something similar: information is written in files, files are organized in directories, and eventually when in even more complex structures named databases. Java provides classes to read information from files and databases and classes to write files and write information to databases. Databases have been mentioned in previous chapters, and Chapter 9 introduced a simple example using an Apache Derby in-memory database to show you how heavy dependencies like databases can be mocked to allow unit testing. This chapter is not about using databases, because writing Java applications to use databases is an advanced topic and would require that you install extra software. Instead, the chapter focuses on reading and writing files and the many ways in which this can be done.