判斷網址是否存在,不存在印出response code.

10:35 上午 0 Comments

public class UrlTest {
public static void main(String[] args) {
URL url;
try {
url = new URL("http://www.benq.com.tw/service/bbd/drviers_wireless.htm");
try {
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
System.out.println("reponse code : " + huc.getResponseCode());
} catch (IOException e1) {
//無效連結
e1.printStackTrace();
}
} catch (MalformedURLException e) {
//無效連結
e.printStackTrace();
}
}
}

0 意見: