springMVC中文件下载的核心内容

File zip = new File(zipPath);

    logger.info("createProjectTool file downloading,fileName:" + zip.getName()+ ",absolute path of temporary generating file:"+ zipPath);
    response.setCharacterEncoding("utf-8");
    onse.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment;fileName=" + zip.getName());
    response.setHeader("Content-Length", String.valueOf(zip.length()));
     byte[] bytes =new byte[1024];
    length =0;
    inputStream = new FileInputStream(zip);
    outputStream = new BufferedOutputStream(response.getOutputStream());
    while (-1 != (length = inputStream.read(bytes))) {
        outputStream.write(bytes, 0, length);
    }

你可能感兴趣的:(spring,springmvc)