URL url = new URL("http://localhost:8080/image/sample/M-111.png");
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
String message = urlcon.getHeaderField(0);
int responseCode = urlcon.getResponseCode();
String responseMessage = urlcon.getResponseMessage();
System.out.println(message);
System.out.println(responseCode);
System.out.println(responseMessage);
如果文件存在:
HTTP/1.1 200 OK
200
OK
如果文件不存在:
HTTP/1.1 404 Not Found
404
Not Found