zoukankan      html  css  js  c++  java
  • 下载压缩文件并打包

    public String downloadjsglfj(){
    String id = getServletRequest().getParameter("id");
    String jsmc = getServletRequest().getParameter("jsmc");
    List<FjxxbVO> list=fjxxService.getJsglFjByFId(id,"jsglfj");
    if(list.size()>0){
    try {
    fileName= jsmc+".zip";
    this.inputStream=SftpUtils.batchDownload(list);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }else{
    return null;
    }


    return SUCCESS;
    }

    --------------------------

    public static InputStream batchDownload(List<FjxxbVO> list){
    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    try{
    sftp = connect(ftpServer, ftpPort, ftpAccount, ftpPassword);
    ZipOutputStream out = new ZipOutputStream(bos);
    byte[] buf = new byte[4096];
    for (FjxxbVO fjxxbVO : list) {
    InputStream in = null;
    try {

    in=sftp.get(fjxxbVO.getLj()+"/"+fjxxbVO.getSsmc());

    out.putNextEntry(new ZipEntry(fjxxbVO.getOrgname()+"."+fjxxbVO.getWjlx()));

    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    }
    out.closeEntry();
    in.close();


    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    //inputStream=sftp.get(fileDir);
    out.close();
    bos.close();

    } catch (FileNotFoundException e) {
    } catch (Exception e) {
    e.printStackTrace();
    }

    return new ByteArrayInputStream(bos.toByteArray());

    }

  • 相关阅读:
    Oauth2.0认证原理
    互联网开放平台API安全设计
    API接口幂等性框架设计
    防盗链&CSRF&API接口幂等性设计
    ElasticSearch高可用集群环境搭建和分片原理
    SpringBoot2.0+ElasticSearch网盘搜索实现
    Elasticsearch6.4.3文档的映射
    中文分词器
    C# 插件
    JavaScript 网址
  • 原文地址:https://www.cnblogs.com/wanghongwei123/p/7154308.html
Copyright © 2011-2022 走看看