文件下载

来源:互联网 发布:sql语句的执行顺序 编辑:程序博客网 时间:2024/06/06 15:23

public void urlBrown(HttpServletResponse response) throws Exception {// 文件下载// 获得绝对路径 创建文件对象// String path =// ServletActionContext.getServletContext().getRealPath("/front/报错级.txt");// 部署路径String path = ConfigProperties.getInstance().getProperties("ftpdownloadpath");TclFilesData tclFilesData = fileDataService.get(new Integer(info));String p = tclFilesData.getFilepath();File file = new File(path + p);PrintWriter printWriter = response.getWriter();// 通知浏览器以下载的方式打开response.setHeader("content-type", "application/octet-stream");response.setHeader("content-disposition", "attachment;filename="+ URLEncoder.encode(file.getName(), "utf-8"));// 创建和文件相关的输入流BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));// 获得response的输出流// BufferedOutputStream out = new BufferedOutputStream(response// .getOutputStream());// 流的对拷for (int data; (data = in.read()) != -1;)printWriter.write(data);}


0 0
原创粉丝点击