Spring Boot如何读取resource目录下文件呢?
下文笔者讲述读取resource目录下文件的方法及示例分享,如下所示
今天使用java读取resource目录下的文件失败,
那么到底该如何读取resource目录下的文件呢?笔者将一一道来,如下所示
================================================
报错代码:
String templatePath = "/test/index.html";
ClassPathResource resource = new ClassPathResource(templatePath);
File file;
try {
file = resource.getFile();
} catch (IOException e) {
e.printStackTrace();
}
正确的读取resource目录下文件的方法
String templatePath = "/test/index.html"; ClassPathResource resource = new ClassPathResource(templatePath); BufferedInputStream bis = new BufferedInputStream(resource.getInputStream());
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


