首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

上载有关问题

2012-12-28 
下载问题下载文件 public String download() throws Exception { OutputStream out null String filena

下载问题
下载文件

 public String download() throws Exception { OutputStream out = null; String filename = ""; String path = getRequest().getSession().getServletContext().getRealPath(Constant.EXCEL_DOWNLOAD_PATH);  File file = new File(path); if (file.exists()) {     filename = file.getName();     // set response head     filename = new String(filename.getBytes("GBK"), "ISO-8859-1");     getResponse().setContentType("application/octet-stream;charset=GBK");     getResponse().setHeader("Content-disposition","attachment;filename=" + filename);     out = FileUtils.exportFile(file, getResponse().getOutputStream());      } else {        filename = "文件不存在.txt";        // set response head        filename = new String(filename.getBytes("GBK"), "ISO-8859-1");        getResponse().setContentType("application/octet-stream;charset=GBK");        getResponse().setHeader("Content-disposition","attachment;filename=" + filename);        out = getResponse().getOutputStream();     }         return null;}


通过设置  getResponse()
      .setContentType("application/octet-stream;charset=GBK");
     getResponse().setHeader("Content-disposition",
      "attachment;filename=" + filename);
将下载文件简化



FileUtil.java见附件

热点排行