Stringannexid=request.getParameter("id")==null?"":request.getParameter("id");Stringname=request.getParameter("annexpath")==null?"":request.getParameter("annexpath");Syste...
String annexid=request.getParameter("id")==null?"":request.getParameter("id");
String name=request.getParameter("annexpath")==null?"":request.getParameter("annexpath");
System.out.println("xiazai name="+name);
OutputStream fos = null;
InputStream fis = null;
String path=request.getRealPath("")+"/annex/"+name;
String path1=name.substring(name.lastIndexOf("/")+1,name.length());
log.info("path11111111111:"+path1);
log.info("path:"+path);
File uploadFile = new File(path);
try {
fis = new FileInputStream(uploadFile);
fos = response.getOutputStream();
response.reset();
response.setContentType("application/octet-stream");
// 这个就就是弹出下载对话框的关键代码
response.setHeader("Content-disposition", "attachment;filename="
+ URLEncoder.encode(path1, "UTF-8"));
// 这个地方的同上传的一样。我就不多说了,都是用输入流进行先读,然后用输出流去写,唯一不同的是我用的是缓冲输入输出流
byte[] b = new byte[1024];
int len=0;
while ((len = fis.read(b)) > 0)
fos.write(b, 0, len);
fis.close();
fos.close();
} catch (FileNotFoundException e) {
log.error(e);
}catch (IOException e) {
log.error(e);
}弹出框子一直报空指针异常,如何解决
展开