判断远程网络上的文件是否存在

URL url = null;
       URLConnection urlCon;
       InputStream inStream;// 你只需判断这个变量值 .
       try {
        url = new URL(
          "http://"+host+":8080/shareResource/test.xml");
        urlCon = url.openConnection();
        inStream = urlCon.getInputStream();
        if (inStream != null) {
         System.out.println(host+"中有xml文件,且tomcat已启动");
        }
       } catch (java.net.ConnectException e) {
        System.out.println(host+"tomcat没有启动");
       }
     

==============

 

host为ip  

你可能感兴趣的:(毕业设计的问题学习)