回复 楼主 fujinliang 的帖子
有跟楼主同样的问题。。。。本人用JSP写个下载,求高手帮帮忙
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="*" %>
<%
request.setCharacterEncoding("GBK");
String tempFileName="1.txt";//文件名字
byte b[]=new byte[10240];
//建立文件
File fileLoad=new File(application.getRealPath("/Upload"),tempFileName);
response.setHeader("Content-disposition","attachment;filename="+tempFileName);
response.setContentType("application/x-msdownload");
long fileLength=fileLoad.length();
String length=String.valueOf(fileLength);
response.setHeader("Content_Length",length);
//读取文件并发送到客户端下载
OutputStream o=response.getOutputStream();
FileInputStream in=new FileInputStream(fileLoad);
int n=0;
while((n=in.read(b))!=-1){
o.write(b,0,n);
}
in.close();
o.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>下载</title>
</head>
<body>
</body>
</html>
为什么那个tempFileName是中文的时候就不能下载呢?