在java中测试访问连接是否可用
如何在java里测试http://localhost:8080/XXX这个路径是否能连接不会返回404??
[解决办法]
public static boolean checkUrl(String url){ try { HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection(); int respCode = con.getResponseCode(); return respCode==404 ? false : true; //return respCode!=200 ? false : true; } catch (Exception e) { e.printStackTrace(); return false; } }