Spring Boot 读取 resource 下文件

支持linux下读取

import org.springframework.core.io.ClassPathResource;
 
public InputStream getCertStream() {
          try {
            ClassPathResource classPathResource = new ClassPathResource("config/apiclient_cert.p12");
            //获取文件流
            InputStream certStream = classPathResource.getInputStream();
            this.certData = IOUtils.toByteArray(certStream);
            certStream.read(this.certData);
            certStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
   }

猜你喜欢

转载自www.cnblogs.com/fengqiaoyebo/p/10120790.html