实现文件的下载时出现的几个问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 16:15:34
文件名为中文时,下载该文件无法识别文件类型。另外,是若下载文件格式为txt文本格式就会报错,是什么原因啊?

SubForm form = (SubForm)actionForm;
TextBean bean = new TextBean();
if(form.getPid() != null){
bean = BookService.getText(form.getPid());
}
if(form.getId() != null){
bean = BookService.getSubText(form.getId());
}
response.setContentType("text/plain");
String fileName = new String(bean.getFileName().getBytes(),"ISO8859-1");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + ".txt\"");
DataOutputStream output = null;
output = new DataOutputStream(response.getOutputStream());
output.write(bean.getContent().getBytes());
output.close();
return null;
看你指定setContentType没有

String filename= new String(tempfilename.getBytes("GBK"),"ISO8859_1");