未处理的异常类型filenotfoundexception,编译问题

问题描述 投票:0回答:1

我正在尝试从磁盘读取文件,但是我面临编译错误在

 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;
            }

        });
java file-io java-io fileinputstream
1个回答
1
投票

如果您真的想重新抛出该异常,请将其包装在RuntimeException中。

    } catch (Docx4JException | IOException e) {
        e.printStackTrace();
        log.error("Błąd Docx4J: {}", e);
        throw new RuntimeException(e);
    }

顺便说一句,您在{}中缺少一个log.error


0
投票

如果您真的想重新抛出该异常,请将其包装在RuntimeException中。

    } catch (Docx4JException | IOException e) {
        e.printStackTrace();
        log.error("Błąd Docx4J: **{}**", e);
        throw new RuntimeException(e);
    }
© www.soinside.com 2019 - 2024. All rights reserved.