java下载文件中文乱码情况解决方法
来源:互联网 发布:fifaonline317卡数据 编辑:程序博客网 时间:2024/06/05 10:53
@RequestMapping(value="/downfile",method=RequestMethod.GET)public String download(String filename,HttpServletRequest req,HttpServletResponse res) throws UnsupportedEncodingException{filename = new String(filename.getBytes("iso-8859-1"),"utf-8"); System.out.println(filename+"******");String realpath=req.getSession().getServletContext().getRealPath("down");File file = new File(realpath+"/"+filename);if(file.exists()){//下载 读 输入流 ---》(写响应流)客户端res.setContentType("application/octet-stream"); String headerValue = "attachment;"; headerValue += " filename=\"" + encodeURIComponent(filename) +"\";"; headerValue += " filename*=utf-8''" + encodeURIComponent(filename);res.addHeader("Content-Disposition", headerValue);try {FileInputStream is=new FileInputStream(file);byte[] arr=new byte[is.available()];is.read(arr);//写到响应流OutputStream os=res.getOutputStream();os.write(arr);os.close();is.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}return "downsucc";}public static String encodeURIComponent(String value) { try { return URLEncoder.encode(value, "UTF-8").replaceAll("\\+", "%20"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; }}
阅读全文
0 0
- java下载文件中文乱码情况解决方法
- java下载中文文件名乱码的解决方法
- java下载中文文件名乱码的解决方法
- Struts2文件下载遇到中文乱码、中文丢失的解决方法
- Java读取中文文件出现乱码解决方法
- Java 下载文件(如Excel)文件名中文乱码或缺失解决方法
- java 文件下载且解决中文乱码
- Java下载文件,文件名中文乱码问题
- java文件下载包含中文是乱码
- Java文件下载之解决中文乱码
- Java 实现文件下载--解决中文乱码
- javaweb网站下载文件中文文件名乱码解决方法
- 文件下载中文乱码
- JAVA中文乱码解决方法
- Java中文乱码解决方法
- java中文乱码解决方法
- JAVA中文乱码解决方法
- Java中文乱码——7、Tigo文件下载乱码
- 安卓shape背景
- 使用cordova插件时要注意配置config.xml
- 二叉树的一些基础知识及创建、遍历
- 三角形代码
- css tips
- java下载文件中文乱码情况解决方法
- Mysql :Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
- 数据透视后,Excel单元格默认格式突然变成日期了
- RTC hwclock date 命令使用
- 获取cookie后将cookie放在下一次请求
- deamon(守护进程)的实现
- C语言笔记——头文件string.h中内置的常用字符串操作函数
- IPUtil
- Questions about LogisticRegregation(1)