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();
}
}