zoukankan      html  css  js  c++  java
  • JAVA 下载单个文件

        public void toDownLoad(String ape505, HttpServletRequest request, HttpServletResponse response) throws IOException {
            //获取文件后缀名
            String ext = ape505.substring(ape505.lastIndexOf(".") + 1).toUpperCase();
            // 读到流中
            // 文件的存放路径
            InputStream inStream = new FileInputStream( request.getSession().getServletContext().getRealPath("/upload/本级预警处理上传目录/")+ape505);
            // 设置输出的格式
            response.reset();
            response.setContentType(ext);
            response.addHeader("Content-Disposition", "attachment; filename="" + ape505 + """);
            // 循环取出流中的数据
            byte[] b = new byte[100];
            int len;
            try {
                while ((len = inStream.read(b)) > 0) {
                    response.getOutputStream().write(b, 0, len);
                }
                inStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    sql刷题day03
    sql刷题day2
    sql刷题day1
    Vue学习
    HashMap学习笔记整理
    数组问题(鸽巢原理、数字交换、链表寻环)
    mybatis参数设置问题
    codeforces 327A
    codeforces 189A
    codeforces-455A
  • 原文地址:https://www.cnblogs.com/lintu-kong/p/13474526.html
Copyright © 2011-2022 走看看