文件下载实例
来源:互联网 发布:淘宝店铺折扣价设置 编辑:程序博客网 时间:2024/05/17 08:22
HttpServletResponse response = ServletActionContext.getResponse();InputStream inputStream = null;OutputStream outputStream = null;msg = "文件下载成功";try {response.setContentType("application/x-msdownload;charset=UTF-8");response.setHeader("Content-Disposition","attachment;filename=" + java.net.URLEncoder.encode("aa.ini", "UTF-8"));inputStream = dataInfo.getFileContent().getBinaryStream();outputStream = new BufferedOutputStream(response.getOutputStream());byte[] buf = new byte[1];int len = 0;try {while((len = inputStream.read(buf)) != -1) {outputStream.write(buf, 0, len);outputStream.flush();}} catch (IOException e) {e.printStackTrace();msg = "文件写入时出错!";}} catch (SQLException e) {e.printStackTrace();msg = "读取Blob文件时出错";} catch (IOException e1) {e1.printStackTrace();}finally{try {inputStream.close();} catch (IOException e) {msg = "关闭流时出错";e.printStackTrace();}try {outputStream.close();} catch (IOException e) {msg = "关闭流时出错";e.printStackTrace();} } //end try
前台代码:
<a href='${pageContext.request.contextPath}/stationLocationAction!downLoadFile.action'>下载</a>
0 0
- mvc文件下载实例
- FTP下载文件实例
- 文件下载实例
- PHP文件下载实例
- 文件下载小实例
- struts2文件下载实例
- php下载文件实例
- java 文件下载实例
- Servlet 文件下载实例
- LR下载文件脚本实例
- [Java]文件下载实例方法
- WebApi 文件下载功能实例
- HttpUrlConnection、HttpClient下载文件实例
- C#文件下载、文件分块下载实例(一)
- Android实例:多线程文件下载+在线音乐播放+清除下载文件
- 实例-用JSF实现文件下载
- 如何实现多文件下载(实例)
- 实例-用JSF实现文件下载
- Web应用该在哪种云服务上运行?
- iOS之用NSTimer定时刷新按钮的文字,避免按钮闪烁的办法
- 简单的Android笔记sharePreferences和Editor
- UVa12097 - Pie
- Qt5基本对话框
- 文件下载实例
- TOOLBAR和沉浸式状态栏入门
- Ubuntu中crosstool-ng编译出错:[ERROR] gtype-desc.c:8829:18: error: subscripted value is neither array nor
- JavaScript 闭包详解
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- 数据库原理----学习目标
- 列表小结
- Lucene的几种分词系统
- RAC Wait Event: gcs log flush sync