I'm wondering why you still can read bytes from already closed ByteArrayOutputStream
. Doesn't this line from docs mean the opposite?
public void close ()
: Closes this stream. This releases system resources used for this stream.
Sample code:
String data = "Some string ...";
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(bOut);
dOut.write(data.getBytes());
dOut.close();
System.out.println("Length: " + bOut.toByteArray().length);
System.out.println("Byte #2: " + bOut.toByteArray()[2]);
Output:
Length: 15
Byte #2: 109
Am I doing something wrong?