Hint: working with files for lab 08
Reading a file
There are plenty of class examples of this. Be sure to use a FileReader (as covered in class as opposed to any other way to read from a text file).
Writing to a file
There are a number of class examples for this. Remember to instantiate a PrintWriter using a FileOutputStream. Then it is just like using System.out
Appending to a file
- To add text to the end of a file, when creating a FileOutputStream, add true to the arguments to the new command (as done in class example).
- If the previous file does not end on a blank line (which is what is true for this lab), you should add a "\n" to the beginning of your output to have the new data start on a new line
Copying a file
- If it is a clean copy, see the class example. You can just read then write each line.
- If you are modifying the file, you need to change the line that has the data on it. The rest of the lines are just read and written as is