1. Does the compiler care about the name of the input file on disk or in other words, do you get a compile time error if the file does not exist?
|
No |
2. What kind of error is caused by entering the wrong file name for the input file? (compile, run-time, or logic). Explain why?
|
run-time FileNotFoundException |
3. How many output streams are you creating in your program?
|
2 - note that System.out is an output stream but you are not
CREATING it, you're just using it. |
4. Copy one statement that opens a file for output in your program and place it here.
|
myBadFileWriter = new FileWriter (badOutpuFileName); |
5. What happens when you run this program and the output file already exists? Try it.
|
it is written over |
6. Alter the line in Q4 so that it opens the file for appending records instead of what happens in item 5 and write it here. Try it.
|
myBadFileWriter = new FileWriter
(badOutpuFileName,true); |
7. Since Part 2 is expected to run after the first program, is there any need to check for exceptions?
|
yes |
a. If so, which exceptions would you still check for and why?
|
empty file |
b. If not, why not?
|
|
8. Does your answer to number 7 change if this code is part of a second program, but that we have been told that we can assume that the data is all valid integers one value per line. Why or why not?
|
second program implies separate
program so you would still have to check for
a FileNotFound Exception |
9. We generally do not explicitly close files that we have opened for the read operation. What do you think will happen if you close a file that you opened for reading? Try it.
|
nothing |
10. What happens if you try to read from the file after it has been explicitly closed?
|
you can't read from it any more |