public void download() throws Exception{
String filename = "download.txt";
filename = URLEncoder.encode(filename, "utf-8");
String path = "E:/download.txt";
File file = new File(path);
HttpServletRequest reuqest = ServletActionContext.getRequest();
HttpServletResponse respone = ServletActionContext.getResponse();
respone.setContentLength((int)file.length());
respone.reset();
respone.setContentType("application/octet-stream");
respone.setHeader("Content-Disposition", "attachment;filename=\""+filename+"\"");
respone.setHeader("Connection", "close");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream buffer = new BufferedInputStream(fis);
byte[] b = new byte[1024];
long k = 0;
OutputStream os = respone.getOutputStream();
while(k < file.length()) {
int j = buffer.read(b, 0, 1024);
k += j;
os.write(b);
}
os.flush();
}
String filename = "download.txt";
filename = URLEncoder.encode(filename, "utf-8");
String path = "E:/download.txt";
File file = new File(path);
HttpServletRequest reuqest = ServletActionContext.getRequest();
HttpServletResponse respone = ServletActionContext.getResponse();
respone.setContentLength((int)file.length());
respone.reset();
respone.setContentType("application/octet-stream");
respone.setHeader("Content-Disposition", "attachment;filename=\""+filename+"\"");
respone.setHeader("Connection", "close");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream buffer = new BufferedInputStream(fis);
byte[] b = new byte[1024];
long k = 0;
OutputStream os = respone.getOutputStream();
while(k < file.length()) {
int j = buffer.read(b, 0, 1024);
k += j;
os.write(b);
}
os.flush();
}