从服务器上下载压缩包

来源:互联网 发布:电脑软件服务打不开 编辑:程序博客网 时间:2024/06/03 17:22
  public void exportResult() throws Exception {

    try {

      OutputStream out = response.getOutputStream();
      InputStream stream = getClass().getClassLoader()
          .getResourceAsStream("static/templet/importPhoto.zip");
      File targetFile = new File("批量导入模板.zip");
      FileUtils.copyInputStreamToFile(stream, targetFile);

      String zipname = "压缩包.zip";
      response.setCharacterEncoding("UTF-8");
      response.setContentType("application/octet-stream; charset=UTF-8");
      response.addHeader("Content-Disposition",
          "attachment; filename=\"" + new String(zipname.getBytes("GB2312"), "ISO8859-1") + "\";");
      response.getOutputStream().write(FileUtils.readFileToByteArray(targetFile));
    } catch (Exception e) {
      e.printStackTrace();
    }

  }
原创粉丝点击