我正在尝试一些新的Java 7 IO特性。实际上,我正在尝试检索文件夹中的所有XML文件。但是,当文件夹不存在时,会抛出异常。如何使用新的IO检查文件夹是否存在?
public UpdateHandler(String release) {
log.info("searching for configuration files in folder " + release);
Path releaseFolder = Paths.get(release);
try(DirectoryStream<Path> stream = Files.newDirectoryStream(releaseFolder, "*.xml")){
for (Path entry: stream){
log.info("working on file " + entry.getFileName());
}
}
catch (IOException e){
log.error("error while retrieving update configuration files " + e.getMessage());
}
}