1. 程式人生 > >spring讀取不到resources下面的檔案

spring讀取不到resources下面的檔案

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");