【发布时间】:2018-03-06 10:20:58
【问题描述】:
我使用 spring 的 ResourceLoader 来遍历 jar 中的文件。但我想知道文件的类型(目录或文件)。
Resource resource = defaultResourceLoader.getResource(templatePathPrefix + File.separator + templateSourcePath);
File templateSourceFile = null;
try {
//throws java.io.FileNotFoundException:
templateSourceFile = resource.getFile();
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("Cannot find file " + resource, e);
}
if (templateSourceFile.isDirectory()) {
System.out.println("it is directory");
} else {
System.out.println("it is just file");
}
我知道:
resource.getInputStream()
可以获取文件的内容。但我想知道文件的类型。
【问题讨论】:
标签: java spring spring-boot jar filenotfoundexception