以下程序從時間服務器獲取時間有什麼問題。Java:套接字編程示例
public class SocketTest
{
public static void main(String[] args)
{
Socket s = new Socket(「time-A.timefreq.bldrdoc.gov」, 13);
BufferedReader in = new BufferedReader(
new InputStreamReader(s.getInputStream()));
String line;
do
{ line = in.readLine(); //read line of text from socket
if (line != null) System.out.println(line);
}
while(line != null);
}
}
哎呀!謝謝@aioobe – rohit 2010-10-17 05:37:48
s.close()應該可能在finally塊內。 – 2010-10-17 05:52:36
是的,我同意。 :-) – aioobe 2010-10-17 05:55:02