显示图片
Posted NarcisoForHer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显示图片相关的知识,希望对你有一定的参考价值。
@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(); } } } }
以上是关于显示图片的主要内容,如果未能解决你的问题,请参考以下文章
Swift新async/await并发中利用Task防止指定代码片段执行的数据竞争(Data Race)问题