JAVA获取远程文件

来源:互联网 发布:unix网络编程2 pdf 编辑:程序博客网 时间:2024/06/06 03:54
//path,如:http://xxxx/a.flv
public boolean getExistsUrl(String path){    try {        URL url = new URL(path);        HttpURLConnection httpURLConnection = null;        httpURLConnection = (HttpURLConnection) url.openConnection();        Long size=Long.parseLong(httpURLConnection.getHeaderField("Content-Length"));        if (size>3000){            System.out.println("存在");            return true;        }
       //其它不细写了,
//httpURLConnection从这个对象中可以获取很多东西了
    } catch (Exception e) {        e.printStackTrace();    }    return false;}
 
原创粉丝点击