首页 > 编程语言 > 详细

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

时间:2016-08-15 11:32:50      阅读:681      评论:0      收藏:0      [点我收藏+]
       
       方法一:
       URL serverUrl = new URL("http://localhost:8090/Demo/clean.sql"); HttpURLConnection urlcon = (HttpURLConnection) serverUrl.openConnection(); String message = urlcon.getHeaderField(0); if (StringUtils.hasText(message) && message.startsWith("HTTP/1.1 404")) { System.out.println("不存在"); }else{ System.out.println("存在"+message); } 方法二: URL url = new URL("http://localhost:8090/Demo/clean.sql"); HttpURLConnection urlcon2 = (HttpURLConnection) url.openConnection(); Long TotalSize=Long.parseLong(urlcon2.getHeaderField("Content-Length")); if (TotalSize>0){ System.out.println("存在"); }else{ System.out.println("不存在"); }

 

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

原文:http://www.cnblogs.com/luckydog1/p/5772259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!