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());

    }

  • 相关阅读:
    通过elasticsearch对日志进行搜索热词统计
    登陆获取shell时的配置文件加载过程
    linux共享库加载
    linux安全相关
    ELK常用API使用方法
    linux bash缓存
    redis主从架构及redis集群
    排查电脑的网络问题
    Logstash添加Protobuf解析插件
    Macaca上手体验
  • 原文地址:https://www.cnblogs.com/wanghongwei123/p/7154308.html
Copyright © 2011-2022 走看看