远程文件打包下载

阅读更多

1、根据网络地址获取输入流

URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
InputStream inputStream = conn.getInputStream();

 2、多文件打包成ZIP,输出流到前台进行下载

       byte[] buffer = new byte[1024];  ;   
       ZipOutputStream out = new ZipOutputStream(response.getOutputStream());   
  
       //需要打包的文件  
       File[] file1 = {new File("e:/a.txt"),new File("e:/b.txt"),new File("e:/aa.txt"),new File("e:/bb.txt")};   
       for(int i=0;i0) {   
           out.write(buffer,0,len);    
          }   
           out.closeEntry();   
           fis.close();   
       }   
        out.flush();
        out.close();     
    }  

你可能感兴趣的:(java,文件下载,网络文件,打包)