I was expecting the following code to throw an exception when I goto write data to the Stream:
File file = new File("test.txt");
FileOutputStream fs = new FileOutputStream(file);
OutputStreamWriter ow = new OutputStreamWriter(fs);
BufferedWriter writer = new BufferedWriter(ow);
fs.close();
try {
ow.write(65);
writer.write("test");
} catch (Exception e) {
e.printStackTrace();
}
I realize that I should close the BufferedWriter, but in my current environment, it may be possible for the FileOutputStream to be closed before the BufferedWriter is closed. Shouldn't the FileOutputStream be throwing an IOException which should move up the chain until it hits my try/catch block and print the stack trace?
If I try to call fs.write(65), then it throws an exception.