1. 程式人生 > >Spring Boot 讀取 resource 下檔案

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