p****d 发帖数: 2183 | 1 傻问题,牛人别笑:
try {
Socket sock = new Socket("xxx.xxx.xxx.xxx",80);
} catch (IOException e) {
e.printStackTrace();
}
我需不需要在catch块里写sock.close()?要是创建没有成功,是不是就是说socket为空,
那我也不需要在catch里显式的释放? | L*********r 发帖数: 92 | 2 Socket oSocket = null;
try
{
oSocket = new new Socket("xxx.xxx.xxx.xxx",80);
}
finally
{
//assume the implementation of socket close is elegant
if(oSocket!=null)
{
oSocket.Close();
}
} |
|