springboot jar 部署到linux以后 获取类资源文件问题-- 仅限linux 下 状况比较特殊 须要获取打到jar内的 讲台资源 只能经过流获取,根据路径获...

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

 

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

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 .net

 

 

 

/** *任意文件下载   只能经过 * @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();    }}
相关文章
相关标签/搜索