I am trying to read file from disk however I am facing compilation error on
catch (Docx4JException | IOException e) {
e.printStackTrace();
log.error("Błąd Docx4J: ", e);
throw e;
}
unhandled exception type filenotfoundexception Any ideas?
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;
}
});
If you really want to re-throw the exception, wrap it inside RuntimeException.
} catch (Docx4JException | IOException e) {
e.printStackTrace();
log.error("Błąd Docx4J: {}", e);
throw new RuntimeException(e);
}
Btw, you are missing a {}
in log.error