While working on BufferedOutputStream
found it does not throw an IOException
when we wrote on it after closing the stream.
To verify my result, i checked FileOutputStream
found it is throwing IOException
once we try to write on it after closing it.
public class Test {
public static void main(String[] args) {
try {
// Created a byte[] barry1 barry2
byte[] barry1 = { '1', '3' };
byte[] barray2 = { '2', '4' };
OutputStream os = new BufferedOutputStream(
new FileOutputStream("abc.txt", false));
// Writing to stream
os.write(barry1);
os.close();
os.write(barray2); // this suceeds - bug
os = new FileOutputStream("abc.txt", true);
//Writing to stream
os.write(barry1);
os.close();
os.write(barray2); // crashes here, correct.
} catch (Exception e) {
e.printStackTrace();
}
}
}
Could some one help me on this, Why this behavior is different ?