2014-08-28 1 views
0

클라이언트에 표시 할 URL이 많습니다. 하지만 기존 개체 (내 상황에서는 이미지)에 대한 URL을 선택해야합니다. 누군가 내 URL이 저장 장치에서 삭제되지 않은 이미지를 참조한다면 어떻게받을 수 있습니까?url이 기존 객체를 참조하는지 확인

+0

응답 코드가 도움이 될 수를 – SparkOn

답변

1

URL url = new URL("http://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg"); 
HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 
int statusCode = connection.getResponseCode();//OK if returned value is 200 
1

같은 대해 당신은 스트림 열려고 수있는 방법 :

public static boolean exists(URL url) throws IOException { 
    try { 
     InputStream inputStream = url.openStream(); 
     return inputStream != null; 
    }catch (FileNotFoundException e){ 
     return false; 
    } 
} 

public static void main(String[] args) throws Exception { 
    System.out.println(exists(new URL("https://www.google.de/images/srpr/logo11w.png"))); 
    System.out.println(exists(new URL("https://www.google.de/images/srpr/foo.png"))); 
} 
관련 문제