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


       
       方法一:
       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("不存在"); }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM