I am wondering why you can still read bytes from an already closed ByteArrayOutputStream . Doesn't this line of documents mean the opposite?
public void close () : Closes this stream. This frees up the system resources used for this thread.
Code example:
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
Am I doing something wrong?
source share