中文文件名文件无法下载 大虾来解答

<%@ page contentType="text/html; charset=UTF-8" language="java"
pageEncoding="UTF-8" %>
....
File file = new File(filePath); //filePath D:/新建_20091127135611.txt
FileInputStream bis = new FileInputStream(file);
response.setContentType("APPLICATION/OCTET-STREAM");
response.setCharacterEncoding("utf-8");
System.out.println(fileName);//新建_20091127135611.txt
response.setHeader("Content-disposition", "attachment; filename= "+fileName);
........

下载提示 出现了下图 我看不懂得东西

打开没有问题 保存出错

[b]问题补充:[/b]
哎呀 试该的都试啦 还是不行

文件下载时,对于这种有可能下载文件名字长度超过17个字符的情况会出现文字截段的情况,所以对于中文名字应当进行一下转码;参考lovewhzlq 的答案

中文名的话要转换一下

fileName = new String(name.getBytes(),"ISO8859-1");

1.设置页面编码
<%@ page contentType="text/html;charset=gb2312" language="java"%>

2.修改$TOMCAT/conf/server.xml文件中
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="gb2312"/>

3.重新启动Tomcat。

如果页面使用UTF-8编码,修改gb2312为UTF-8既可。

response.setHeader("Content-disposition", "attachment; filename="+[color=red]URLEncoder.encode(fileName,"utf-8")[/color]);

new String(fileName.getBytes("gb2312"), "ISO8859-1");

楼上答案的可以实验下 给你两个连接看看 http://webcenter.hit.edu.cn/articles/2009/04-01/04193356.htm http://china.manufacturer.com/article/study_for_character_encoding_java.htm