我正在尝试从磁盘读取文件,但遇到编译错误 上
catch (Docx4JException | IOException e) {
e.printStackTrace();
log.error("Błąd Docx4J: ", e);
throw e;
}
未处理的异常类型 filenotfoundexception 有什么想法吗?
Stream<Path> files = Files.list(Paths.get(genConfig.getDocxJiraReportDirectory()));
files.forEach(file -> {
final WordprocessingMLPackage wordMLPackage;
try {
wordMLPackage = fileGenerator.loadFile(genConfig.getDocxTemplateDirectory(),
params.getTemplateFileName());
FileInputStream fis = new FileInputStream(file.toString());
String data = IOUtils.toString(fis, "UTF-8");
System.out.println(data);
String dataFinal = XmlHelper.GenerateEanImage(data);
Docx4J.bind(wordMLPackage, dataFinal, Docx4J.FLAG_NONE);
String filePath = genConfig.getDocxReportDirectory() + "/" + file.getFileName();
Docx4J.save(wordMLPackage, new File(filePath), Docx4J.FLAG_NONE);
} catch (Docx4JException | IOException e) {
e.printStackTrace();
log.error("Błąd Docx4J: ", e);
throw e;
}
});
最佳答案
如果您确实想重新抛出异常,请将其包装在 RuntimeException 中。
} catch (Docx4JException | IOException e) {
e.printStackTrace();
log.error("Błąd Docx4J: {}", e);
throw new RuntimeException(e);
}
顺便说一句,您在 log.error
中缺少 {}
关于java - 未处理的异常类型filenotfoundException,编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59771187/