Spring Boot 读取 resource 下文件

时间:2021-01-31 01:10:02

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