Spring Boot 读取 resource 下文件

支持linux下读取

import org.springframework.core.io.ClassPathResource;
 
public byte[] getCertStream(String path) {
          try {
            ClassPathResource classPathResource = new ClassPathResource(path);
            //获取文件流
            InputStream stream = classPathResource.getInputStream();
            byte[] content = IOUtils.toByteArray(stream);
            stream.read(content);
            stream.close();
       return content; }
catch (IOException e) { e.printStackTrace(); } }

 

posted @ 2018-12-14 17:55  bookc  阅读(2767)  评论(0编辑  收藏  举报