【发布时间】:2020-07-04 19:37:41
【问题描述】:
我正在尝试从以下路径读取 excel 数据:file:///Users/karen/prog/files/statuses.xlsx
但我经常收到错误消息:
rest-module_1 | 2020-03-24 10:02:04.504 ERROR 72 --- [nio-9090-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file input stream from file: '/Users/karen/prog/files/statuses.xlsx'] with root cause
rest-module_1 |
rest-module_1 | java.io.FileNotFoundException: /Users/karen/prog/files/statuses.xlsx (No such file or directory)
这是我的代码:
public XSSFWorkbook getExcelWorkbook(String path) throws IOException, InvalidFormatException, URISyntaxException {
if (path.startsWith("file://")) {
System.out.println(path);
XSSFWorkbook wb = new XSSFWorkbook(new File(new URI(path)));
return wb;
} else {
XSSFWorkbook wb = new XSSFWorkbook(this.getClass().getResourceAsStream(path));
return wb;
}
}
可能有什么问题?如果我通过终端导航到“文件”文件夹并运行“pwd”-它将显示我上面提到的确切路径。我正在使用 Mac 我对该文件具有读写权限:
我正在从 docker 运行应用程序,这可能是错误吗? 这是我的 docker-compose 文件:
services:
rest-module:
build:
context: ./Status
image: statusimage
ports:
- 9090:9090
volumes:
- ./Status/:/app:delegated
- ./LocalStorage/:/root/local:delegated
【问题讨论】:
-
你能说明你是如何设置路径的吗?
-
我正在从 config.yml 文件中读取它
-
当然可以,我可以看看你是如何设置和阅读的吗?它是一个 spring-boot 应用程序还是只是简单的 spring?
-
我无法向您展示完整的流程,因为它是多个文件,但这是我读取资源路径的方式:
XSSFWorkbook wb = getExcelWorkbook(getDataServiceConfig().getStatusesResource()); -
它只是简单的 getter 响应字符串
标签: java spring spring-boot docker docker-compose