首页 > 代码库 > 显示图片
显示图片
@SKS_Annotation(cmd = "getCapByNpId") public static void SKS_getCapByNpId(SkSession session, Np req, SkResponse res) { String capPath = null; String filename = null; if(req == null || req.getId() == null || "".equals(req.getId())){ return; } FileInputStream fis = null; OutputStream out = null; try{ capPath = PropertyUtils.getProperty("capPath"); filename = req.getId() + ".jpg"; res.setContentType("application/octet-stream"); File file = new File(capPath + filename); if(!file.exists()){ file = new File(capPath + "404.png"); if(!file.exists()){ return; } res.setHeader("Content-disposition", "attachment;filename=404.png"); }else{ res.setHeader("Content-disposition", "attachment;filename=" + filename); } fis = new FileInputStream(file); int fileLength = fis.available(); // 得到文件大小 byte data[] = new byte[fileLength]; fis.read(data); out = res.getOutputStream(); out.write(data); }catch(Exception e){ e.printStackTrace(); }finally{ if(fis != null ){ try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if(out != null){ try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
显示图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。