jsp下载文件出现的怪问题
<%@ page contentType= "text/html; charset=GBK " %>
<%@page import= "com.cepri.netlynxtest.* "%>
<%@page import= "java.io.* "%>
<%
FileInputStream ins=new FileInputStream( "c:/test/test.txt ");
response.reset();
response.setContentType( "bin;charset=iso8859_1 ");
response.addHeader( "Content-Disposition ", "attachment; filename=\ " " + "test.txt " + "\ " ");
//循环取出流中的数据
OutputStream os = response.getOutputStream();
int size=ins.available();
byte[] b = new byte[100];
int len;
while((len=ins.read(b)) !=-1)
{
len=ins.read(b);
os.write(b,0,len);
}
ins.close();
%>
<html>
<head>
<title>
FileAction
</title>
</head>
<body bgcolor= "#ffffff ">
<h1>
JBuilder Generated JSP
</h1>
</body>
</html>
我要下载的文件test.txt可以下下来,但是下载下来的文件是个空文件,里面什么也没有,那位大侠知道怎么回事?
------解决方案--------------------FileInputStream ins=new FileInputStream( "c:/test/test.txt ");
response.reset();
response.setContentType( "bin;charset=iso8859_1 ");
response.addHeader( "Content-Disposition ", "attachment; filename=\ " " + "test.txt " + "\ " ");
总觉得有问题。。。