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