<%@ page import="java.io.*;"%>
<%
try {

String url = "D:/websrc/aaa.doc";// 实际文件路径 
String name = "默认中文文件名.doc";//显示给用户看的文件名,即ie弹出下载框中提示保存的文件名
response.reset();
response.setContentType("bin");
response.setHeader("Content-Disposition", "attachment; filename="+new String(name.getBytes(),"iso8859-1"));//处理默认文件名的中文问题 ServletOutputStream os = response.getOutputStream();
FileInputStream in = new FileInputStream(url);
byte[] data = new byte[1024];
int temp = -1;
while((temp=in.read(data))!= -1){
os.write(data,0,temp);
os.flush();
}//while//
in.close();
os.close();
} catch(Exception e) {
out.print(e.toString());
}
%>

解决方案 »

  1.   

    我也在找啊!关注,关键是如何让文件流写入到指定的文件夹中,比如使用FILEDIALOG有人回答,可是不甚完整,望补充FileDialog fileDialog=new FileDialog(m_Frame,"另存什么文件?");
    fileDialog.setFile("*.doc");
    fileDialog.setDirectory(".");
    fileDialog.show();
    String strSaveFile;
    if((strSaveFile=fileDialog.getFile())!=null)
    {
    m_FileName.setText(strSaveFile);
    m_Directory.setText(fileDialog.getDirectory());
           }
    else
    {
            m_FileName.setText("取消");
    m_Directory.setText("");
    }
      

  2.   

    但是我在运行过程中出现以下JasperException:
    illegal to have multiple occurrences of contentType with different values (old: text/html;charset=gb2312, new: text/html; charset=gb2312)
    请问是转换的问题吗?该怎么处理呢?
    搞了我好几天了
      

  3.   

    至此时,我仍未解决该问题,不过快了,在此先感谢各位高手的支持!先给大家分数,可以的话交个朋友,上面有我的e_mail.