zoukankan      html  css  js  c++  java
  • springboot jar 部署到linux之后 获取类资源文件问题-- 仅限linux 下 情况比较特殊 需要获取打到jar内的 讲台资源 只能通过流获取,根据路径获取不到指定文件 nullpointExption

    https://blog.csdn.net/qq_27000425/article/details/72897282

    ClassPathResource类,如果没有指定相对的类名,该类将从类的根路径开始寻找某个resource,如果指定了相对的类名,则根据指定类的相对路径来查找某个resource。

    Resource rs = new ClassPathResource("onlyfun/caterpillar/beans-config.xml");
    或者
    Resource rs = new ClassPathResource("beans-config.xml",SpringDemo.class);

    --------------------- 本文来自 qq_27000425 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/qq_27000425/article/details/72897282?utm_source=copy 

    /**
    *任意文件下载 只能通过
    * @author zhangyh
    * @date 2018/9/21 17:56
    * @param [request, response, url]
    * @return void
    *
    */
    public void downloadStream(HttpServletRequest request,HttpServletResponse response, InputStream inputStream,String fileName) {
    try {
    // 以流的形式下载文件。
    InputStream fis = new BufferedInputStream(inputStream);
    byte[] buffer = new byte[fis.available()];
    fis.read(buffer);
    fis.close();
    // 清空response
    response.reset();
    // 设置response的Header
    response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes()));
    //response.addHeader("Content-Length", "" + file.length());
    OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
    response.setContentType("application/octet-stream");
    toClient.write(buffer);
    toClient.flush();
    toClient.close();
    } catch (IOException ex) {
    ex.printStackTrace();
    }

    }
  • 相关阅读:
    史上最全的浏览器 CSS & JS Hack 手册
    JavaScript1.6数组新特性和JQuery的几个工具方法
    用jquery循环map
    javascript强大的日期函数
    用 javascript 判断 IE 版本号
    常见排序算法基于JS的实现
    JavaScript中callee,caller,argument的理解
    apply()方法和call()方法
    虽然我们可能不想对元素应用3D变换,可我们一样可以开启3D引擎
    在移动端上加上代码,让字体变得平滑
  • 原文地址:https://www.cnblogs.com/javajetty/p/9702547.html
Copyright © 2011-2022 走看看