• Java下载文件


    public void downloadFile(){
            String filePath = request.getParameter("filepath");
            try {
                filePath = new String(filePath.getBytes("ISO-8859-1"),"UTF-8");
                String rootPath = request.getSession().getServletContext().getRealPath("/");
                File file = new File(rootPath+filePath);
                String downFileName = file.getName();
                
                InputStream fis = new BufferedInputStream(new FileInputStream(file));
                byte[] buffer = new byte[fis.available()];
                fis.read(buffer);
                fis.close();
                // 清空response
                response.reset();
                // 设置response的Header
                response.addHeader("Content-Disposition", "attachment;filename=" + new String(downFileName.getBytes()));
                response.addHeader("Content-Length", "" + file.length());
                OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
                response.setContentType("application/octet-stream");
                toClient.write(buffer);
                toClient.close();
            } catch (Exception e) {
                log.errorLog("文件下载失败", e);
            }
        }
  • 相关阅读:
    轮询算法
    随机算法
    加权随机算法
    平滑加权轮询算法
    预训练模型与Keras.applications.models权重资源地址
    多通道卷积操作解析
    Squeeze-and-Excitation Networks
    实验数据集概况
    Keras-图片预处理
    Keras常用层
  • 原文地址:https://www.cnblogs.com/shangrongyiweng/p/5554171.html
Copyright © 2020-2023  润新知