• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing ByteArrayOutputStream

 
Richa Sharma
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys


I am using java API ByteArrayOutputStream. How do I close the stream?

The API documentation says that
"Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException".

Will the reset method of ByteArrayOutputStream work instead?


Thanks

 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to close the stream? If you're done writing to it, get the contents using toByteArray() and discard the reference.
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically it's a good idea, sometimes necessary, to close a stream when you're done with it. In the case of a ByteArrayOutputStream though, there's nothing really that needs to be done. So they define close() to do nothing. You're welcome to close the stream by calling close() just like you would for any other stream - it just doesn't do anything. Because there's nothing that needs to be done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic