现在的位置: 首页 > 综合 > 正文

检测端口是否占用

2013年08月09日 ⁄ 综合 ⁄ 共 381字 ⁄ 字号 评论关闭

 import java.net.Socket;
import java.net.URISyntaxException;

public class Test {

 /**
  * @param args
  * @throws URISyntaxException
  */
 public static void main(String[] args) {
  Socket s = null;
  try {
   s = new Socket("localhost", 61616);
   System.out.println(s + "OK");
  } catch (Exception exception) {
   System.out.println(" ERROR");
  } finally {
   try {
    if (s != null)
     s.close();
   } catch (Exception ee) {
   }
  }
 }

}

抱歉!评论已关闭.