我要获得http://136.5.68.7:8080/creport/files/20091111/xlsfiles/aa.txt这个方的aa.txt文件的大小和最后修改时间怎么办..

解决方案 »

  1.   

    看HTTP头,
    Content-Length

    Last-Modified
    服务器一般会给,特别是静态内容
      

  2.   


    java File类里有个修改时间 
    lastModifiedpublic long lastModified()    返回此抽象路径名表示的文件最后一次被修改的时间。    返回:
            表示文件最后一次被修改的时间的 long 值,用该时间与历元(1970 年 1 月 1 日,00:00:00 GMT)的时间差来计算此值(以毫秒为单位)。如果该文件不存在,或是发生 I/O 错误,则返回 0L 
        抛出:
            SecurityException - 如果存在安全管理器,且其 SecurityManager.checkRead(java.lang.String) 方法拒绝对文件进行读取访问
      

  3.   

    要获取这个大小的话,可以这样 URL url=new URL("http://136.5.68.7:8080/creport/files/20091111/xlsfiles/aa.txt");
    URLConnection con = url.openConnection();
    long size = con.getContentLength();//获取连接URL资源的长度
      

  4.   


    他的文件不在本机,而在server上
      

  5.   


     public static void main(String[] args) throws IOException
        {
            String path = "http://136.5.68.7:8080/creport/files/20091111/xlsfiles/aa.txt";
            URL url = new URL(path);
            URLConnection urlConn = url.openConnection();
            
            urlConn.setDoInput(true);
            
    //动态生成的页面是0,未知
            System.out.println(urlConn.getLastModified());
            
            System.out.println(new Date(urlConn.getLastModified()));
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    urlConn.getInputStream()));
            
            StringBuffer receiveData = new StringBuffer();
            
            char[] receive = new char[1024];
            
            int read = 0;
            while ((read = reader.read(receive)) != -1)
            {
                receiveData.append(receive, 0, read);
            }
            
            String rData = receiveData.toString();
            System.out.println(rData);
            
        }