【发布时间】:2020-10-17 16:07:57
【问题描述】:
我的 jar 用于读取和写入 .json 文件。为此,我决定使用一个外部文件来读取和写入。
我的 jar 是通过 docker-compose up 创建的,并在 /a/b/c/d/app.jar 中运行
我要与之交互的 .json 文件在 /homeDir/Documents/file.json 中
JSONObject aJQLs = new JSONObject(IOUtils.toString(new FileInputStream("/Documents/file.json"), "UTF-8"));
但是,我不断收到 FileNotFoundException。
我认为这就像输入文件的绝对路径一样简单。
我收到以下错误日志
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'jiraAutomationController' defined in URL [jar:file:/app.jar!/BOOT-
INF/classes!/com/company/jiraautomation/controller/JiraAutomationController.class]: Instantiation of bean
failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[com.company.jiraautomation.controller.JiraAutomationController]: Constructor threw exception; nested
exception is java.io.FileNotFoundException: /Documents/file.json (No such file or directory)
jar 是否可以按照我想要的方式与外部文件交互?
运行jar时我对文件路径的理解有问题吗?
我在没有 Spring Boot 的情况下进行了快速测试,只是使用普通 Java 来查看我的路径逻辑是否有问题,但它运行良好。
任何见解将不胜感激
【问题讨论】:
-
你能分享你如何访问这个automation_jql.json
-
automation_jql.json 与 file.json 相同。抱歉,我会修改它。
标签: java spring spring-boot jar path