java.net.Socket.close() and getInputStream

H

HK

Hi,

after obtaining an InputStream from a Socket,
do I have to close it seperately or does it
suffice to close the Socket itself?

Thanks,
Harald.
 
G

Gordon Beaton

after obtaining an InputStream from a Socket, do I have to close it
seperately or does it suffice to close the Socket itself?

You should close the InputStream. It will close the Socket for you.

If you wrap the InputStream in another stream type, close that
instead. In other words, always close the *outermost* stream.

/gordon
 
M

Martin A

Gordon said:
You should close the InputStream. It will close the Socket for you.
Is it possible to close a Socket's InputStream but not close the Socket,
and then use its OutputStream for example?
 
G

Gordon Beaton

Is it possible to close a Socket's InputStream but not close the
Socket, and then use its OutputStream for example?

Socket.shutdownInput() in that case.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top