response.addHeader("content-type", "application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename="+file_name);
各参数之间的空格去掉,另外,看一看在建立文件流时是不是存在问题!
response.setHeader("Content-disposition", "attachment; filename="+file_name);
各参数之间的空格去掉,另外,看一看在建立文件流时是不是存在问题!
FileInputStream myFile=null;
File file =null;
try{
String userDir = System.getProperty("user.dir");
strPath = userDir + File.separator + "report"+File.separator+filename;
str = strPath;
file = new File(strPath); if (file.exists()) {
myFile = new FileInputStream(file);
byte[] buf =new byte[1024];
int i;
while ( (i = myFile.read(buf)) != -1 ) {
outputStream.write(buf, 0, i);
}
outputStream.flush();
buf = null;
myFile.close();
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
outputStream.close();
//file.delete();
}
}//end synchronized
}catch (Exception e) {
throw e;
}
%>
可就是在下载后的文件后面多了一空行,源文件没有该空行。
屏蔽掉,会产生一个空文件,但空文件中还是有两个空行,我怀疑是
response.addHeader("content-type", "application/x-msdownload;");
response.setHeader("Content-disposition", "attachment;
这两句的问题。