文件下载 直接上代码
//获取文件名
String fileName="文件名";
//获取文件下载路径
String downPath=request.getSession().getServletContext().getRealPath("file/"+fileName );
//将服务器文件 以字节缓冲流 读入程序
BufferedInputStream in=new BufferedInputStream(new FileInputStream(new File(downPath)));
//设置字符编码集 解决文件名乱码
fileName=URLEncoder.encode(fileName, "UTF-8");
//将文件以字节缓冲流下载到客户端 设置文件响应方式 为 附件
response.addHeader("Content-Disposition", "attachment;fileName="+fileName);
//多部分文件流下载
response.setContentType("multipart/form-data");
//开始下载
BufferedOutputStream output=
new BufferedOutputStream(response.getOutputStream());
//开始进行传输
int length=in.read();
while (length!=-1) {
output.write(length);
length=in.read();
output.flush();
}
output.close();
没了啊