java 下载文件功能
2014-04-08 15:38
375 查看
public String downLoadFileContent() throws IOException{ // 下载网络文件 int bytesum = 0; int byteread = 0; response = CustomerUtil.getResponse(); request = CustomerUtil.getRequest(); String filePath = request.getParameter("filePath");//http://localhost:8080/mypro/img String fileName = request.getParameter("fileName");//201212121212.txt URL url = new URL(filePath+fileName); try { URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); OutputStream fs=response.getOutputStream(); //设置response的编码方式 response.setContentType("application/x-msdownload"); response.setHeader("Content-Disposition","attachment;filename="+new String(fileName.getBytes("gbk"),"iso-8859-1")); response.setHeader("Content-Disposition","attachment;filename="+fileName); byte[] buffer = new byte[1204]; int length; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; fs.write(buffer, 0, byteread); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
本文出自 “小浩” 博客,请务必保留此出处http://zhangchi.blog.51cto.com/5214280/1392282
相关文章推荐
- Java实现文件下载功能
- Java中实现FTP上传下载文件的功能,完整代码
- Java中实现FTP上传下载文件的功能,完整代码
- java实现文件上传,文件下载功能 源码
- java 通过 URL 类和 URLConnection类 以及输入流实现文件下载功能
- java中struts2实现文件上传下载功能实例解析
- Java 文件下载功能 解决中文乱码
- Java Web +Servlet 文件下载功能
- Java中实现FTP上传下载文件的功能,完整代码
- JavaWeb文件上传与下载功能解析
- javaWeb 实现文件下载的功能
- 基于Java的一个简单的文件上传下载功能
- 基于Java的一个简单的文件上传下载功能
- Java文件下载功能实现
- Java如何实现文件打包下载功能
- JXL生成的excel文件+JAVA文件下载功能
- java 下载文件功能
- java—servlet实现文件下载功能
- java 下载文件功能代码例子
- 【转载】Java如何实现文件打包下载功能