spring讀取不到resources下面的檔案
阿新 • • 發佈:2018-12-20
spring打成jar執行時會讀取不到resouces下面的檔案:
private byte[] inputToByte(String path){ byte[] data = null; try { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); Resource resource = resourceLoader.getResource(path); InputStream inputStream = resource.getInputStream(); if (inputStream.available() == 0){ return data; } data = new byte[inputStream.available()]; inputStream.read(data); inputStream.close(); return data; }catch (Exception e){ log.error(e.getMessage()); return data; } }
byte[] bytes = inputToByte("classpath:koala.lic");