springMVC中文件下载的核心内容

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_25484147/article/details/80846410
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);
    }

猜你喜欢

转载自blog.csdn.net/qq_25484147/article/details/80846410
今日推荐