try {
url = new URL("<a href='http://www.baidu.com"' target="_blank">http://www.baidu.com"</a>);
InputStream in = url.openStream();
System.out.println("连接可用");
} catch (Exception e1) {
System.out.println("连接打不开!");
url = null;
}
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
} catch (Exception e) {
System.out.println(“地址链接不可用”);
status = false;
}
return status;
}
public synchronized URL isConnect(String urlStr) {
int counts = 0;
if (urlStr == null || urlStr.length() <= 0) {
return null;
}
while (counts < 5) {
try {
url = new URL(urlStr);
con = (HttpURLConnection) url.openConnection();
state = con.getResponseCode();
System.out.println(counts + “= “ + state);
if (state == 200) {
System.out.println(“URL可用!”);
}
break;
} catch (Exception ex) {
counts++;
System.out.println(“URL不可用,连接第 “ + counts + “ 次”);
urlStr = null;
continue;
}
}
return url;
}
}