转载:http://blog.csdn.net/soundfly/article/details/6177535
没有废话,只有代码。
- java.net.URL url = null;
-
- java.net.URLConnection urlCon;
-
- try {
-
- url = new java.net.URL("http://192.168.0.26:8086/defaultroot/upload/201012211525255316256830418.doc");
-
- urlCon = url.openConnection();
-
- String message = urlCon.getHeaderField(0);
-
- System.out.println(message);
-
- } catch (java.net.MalformedURLException e0) {
-
- } catch (java.io.IOException ie3) {
-
- }
优化代码
- public static boolean exists(String URLName) {
- try {
- HttpURLConnection.setFollowRedirects(false);
- HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
- con.setRequestMethod("HEAD");
- return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }