首页 > 其他 > 详细

下载服务器端EXCEL

时间:2017-02-14 11:50:27      阅读:290      评论:0      收藏:0      [点我收藏+]

public void downLoad(HttpServletResponse response, HttpServletRequest request) {  

     String id = request.getParameter("id");// id  

     CownExcel cownExcel = customerService.getCownExcelID(Integer.parseInt(id));  

   try {    

      String filename = cownExcel.getUrl();   

       filename = filename.substring(filename.lastIndexOf("\\")+1);//获取文件名字某个路径下的    

      // 读到流中    InputStream inStream;

         inStream = new FileInputStream(cownExcel.getUrl());//下载文件的路径    

        // 文件的存放路径    // 设置输出的格式   

       response.reset();   

       response.setContentType("bin");   

       try {     

         response.addHeader("Content-Disposition",       "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));     // 循环取出流中的数据     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();    
     }

   } catch (UnsupportedEncodingException e) {     e.printStackTrace();    }   } catch (FileNotFoundException e) {    e.printStackTrace();   }  }

下载服务器端EXCEL

原文:http://www.cnblogs.com/cuijinlong/p/6396819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!