标签:context int content block trace NPU read ade leo
LocalServletContext localContext = (LocalServletContext) context;
//1.获取到响应对象
HttpServletResponse response = localContext.getResponse();
String FilePath= (String) context.getData("Url");
if(FilePath != null && !"".equals(FilePath)){
File file=new File(FilePath);
if(!file.exists()){
try {
response.sendError(404, "File not found !");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
try {
BufferedInputStream br =new BufferedInputStream(new FileInputStream(file));
byte [] buf=new byte[1024];
int len=0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment;filename="+file.getName());
OutputStream output=new FileOutputStream(file);// 通过对象多态性,进行实例化
while((len=br.read(buf))>0){
output.write(buf, 0, len);
}
output.flush();
br.close();
output.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
标签:context int content block trace NPU read ade leo
原文地址:https://www.cnblogs.com/mayay/p/9473907.html