CHAPTER 8 ■ WRITING AND READING FILES
- FileInputStream objects and FileOutputStream objects use byte arrays to read
from and write to files. - We can load the content of a FileInputStream object into a FileOutputStream
object by using a byte array.
Working with directories, files, and the contents of files might not be the most exciting kind of
programming, but it's often necessary. As you continue your programming career (whether as a
professional or as a hobbyist), you'll almost certainly work with files on a regular basis.
As ever, I encourage you to write a few programs of your own. Here are a couple of ideas to tackle:
- Read the contents of one file and put them in another file.
- Read all the file names within a directory and put them in a file.
- Add full path names to the names of the files in the previous idea.
- Create all the files listed in a file.
- Create all the files listed in a file, but with a different path for each file.
■ Tip As you test files, read and write only from files within a test directory, as we do in this chapter. That
lessens the risk that you'll accidently change a file that could cause a problem. Also, test often, to be sure the files
you work with end up in the right places and have the right contents.