求救 急急急!!!!!!!!!!!!!!!

庞太师 发布于 2013/01/28 11:50
阅读 140
收藏 0

public void downLoad()throws Exception,FileNotFoundException{
        try {
         //newFileName = java.net.URLDecoder.decode(newFileName, "utf8");
            // xmlPath是指欲下载的文件的路径。
         String xmlPath = ServletActionContext.getServletContext().getRealPath("xmlfile");
   File filePath = new File(xmlPath + File.separator + newFileName);
            // 取得文件的后缀名。
            String ext = newFileName.substring(newFileName.lastIndexOf(".") + 1).toUpperCase();

            // 以流的形式下载文件。
            InputStream fis = new BufferedInputStream(new FileInputStream(filePath));
            byte[] buffer = new byte[2048];
            fis.read(buffer);
            fis.close();
            // 清空response
            response.reset();
            // 设置response的Header
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(newFileName.getBytes()));
            response.addHeader("Content-Length", "" + filePath.length());
            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            toClient.write(buffer);
            toClient.flush();
            toClient.close();
        } catch (IOException e) {
         if(e instanceof FileNotFoundException){
    PrintWriter out = response.getWriter();
    out.print("<script>alert('文件不存在或已删除');</script>");
    out.flush();
    out.close();
   }else{
    e.printStackTrace();
   }
        }
    }

 

这是个文件下载的方法,但是执行到  InputStream fis = new BufferedInputStream(new FileInputStream(filePath)); 就跳出去了什么情况求救!!!

加载中
0
子木007
子木007
你倒是把异常弄出来呀
0
z
zhongxh
嗯,看看什么异常
返回顶部
顶部