Is it safe to close a socket without closing it's streams?? I have google it and come to a variety of answers. Java API says that closing a socket also closes it's associated streams. But did we know that they flush before they close??
Printable View
Is it safe to close a socket without closing it's streams?? I have google it and come to a variety of answers. Java API says that closing a socket also closes it's associated streams. But did we know that they flush before they close??
If I remember correctly, most Java SE streams don't require flushing, or if they do they will automatically flush when closed. You'll have to be careful about streams you or someone else write, these may or may not require flushing before closing the stream.