在Java中判断URL地址的图片是否有效,通过以下代码可以实现: String posturl = "http://www.xx.com/1.jpg"; URL url = new URL(posturl); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); urlcon.setRequestMethod("POST"); urlcon.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); if (urlcon.getResponseCode() == HttpURLConnection.HTTP_OK) { System.out.println(HttpURLConnection.HTTP_OK + posturl + ":posted ok!"); bol = true; } else { System.out.println(urlcon.getResponseCode() + posturl + ":Bad post..."); bol = false; }String posturl = "http://" + getImageIP(photonetbarcode) + ":7778/photo/city_center/control/member/" + photonetbarcode + "/" + photonetbarcode + cert_no + "Cert.jpg"; URL url = new URL(posturl); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); urlcon.setRequestMethod("POST"); urlcon.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); if (urlcon.getResponseCode() == HttpURLConnection.HTTP_OK) { System.out.println(HttpURLConnection.HTTP_OK + posturl + ":posted ok!"); } else { System.out.println(urlcon.getResponseCode() + posturl + ":Bad post..."); }