Java 判断远程服务器上文件是否存在

//首先,拼接你的文件路径
String Path = Constants.upload_url + expertDoctor.getDoctorId() +".png";
     
 //然后,判断文件是否存在
      URL url = new URL(Path);
      
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();

      String message = urlcon.getHeaderField(0);

      if (StringUtils.hasText(message) && message.startsWith("HTTP/1.1 404")) {
         //不存在
      }else{
           //存在
      }

你可能感兴趣的:(Java)