如何实现点击按钮下载文件?
文件绝对路径可以从数据库得到,关键是怎么实现点击按钮弹出下载对话框?文件类型未知
------解决方案--------------------String filename = "C:\xxx.xx ";
response.setContentType( "application/x-msdownload ");
response.addHeader( "Content-Disposition ",
"attachment; filename=\ " " + java.net.URLEncoder.encode(filename, "UTF-8 ") + "\ " ");
try {
java.io.OutputStream os = response.getOutputStream();
java.io.FileInputStream fis = new java.io.FileInputStream(filename);
byte[] b = new byte[1024];
int i = 0;
while ( (i = fis.read(b)) > 0) {
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
}
catch (Exception e) {
e.printStackTrace();
}