如何提取jar包中的静态资源文件?

2026-04-10 14:031阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计150个文字,预计阅读时间需要1分钟。

如何提取jar包中的静态资源文件?

项目成功生成jar包,提取jar包中的静态资源。包含以下方法:

public DataResult picRead(HttpServletRequest request, HttpServletResponse response, @RequestParam(path) String path) throws ServletException, IOException { // 读取本地图片输入流}

如何提取jar包中的静态资源文件?

项目打成jar包获取jar包内的静态资源

public DataResult picRead(HttpServletRequest request, HttpServletResponse response,@RequestParam("path") String path) throws ServletException, IOException { //读取本地图片输入流 InputStream inputStream = null; try{ inputStream = new FileInputStream(resultUnZipPath+path); }catch (IOException e){ try { //打成jar包可获取jar包内的静态资源 inputStream = this.getClass().getResourceAsStream("/static/assets/images/imageNotFound.jpg"); }catch (Exception e1){ return new DataResult(RestConst.ErrorCode.EMPTY_PARAM,"未找到图片"); } } int i = 0; while (i == 0){ i = inputStream.available(); } //byte数组用于存放图片字节数据 byte[] buff = new byte[i]; inputStream.read(buff); inputStream.close(); response.setContentType("image/*"); OutputStream out = response.getOutputStream(); out.write(buff); out.close(); return new DataResult(""); }

标签:静态资源

本文共计150个文字,预计阅读时间需要1分钟。

如何提取jar包中的静态资源文件?

项目成功生成jar包,提取jar包中的静态资源。包含以下方法:

public DataResult picRead(HttpServletRequest request, HttpServletResponse response, @RequestParam(path) String path) throws ServletException, IOException { // 读取本地图片输入流}

如何提取jar包中的静态资源文件?

项目打成jar包获取jar包内的静态资源

public DataResult picRead(HttpServletRequest request, HttpServletResponse response,@RequestParam("path") String path) throws ServletException, IOException { //读取本地图片输入流 InputStream inputStream = null; try{ inputStream = new FileInputStream(resultUnZipPath+path); }catch (IOException e){ try { //打成jar包可获取jar包内的静态资源 inputStream = this.getClass().getResourceAsStream("/static/assets/images/imageNotFound.jpg"); }catch (Exception e1){ return new DataResult(RestConst.ErrorCode.EMPTY_PARAM,"未找到图片"); } } int i = 0; while (i == 0){ i = inputStream.available(); } //byte数组用于存放图片字节数据 byte[] buff = new byte[i]; inputStream.read(buff); inputStream.close(); response.setContentType("image/*"); OutputStream out = response.getOutputStream(); out.write(buff); out.close(); return new DataResult(""); }

标签:静态资源