【发布时间】:2021-10-08 00:39:56
【问题描述】:
我确实通过 Tomcat apache 将使用 spring 编写的 java Web 应用程序部署到了 ubuntu linux 服务器。 我创建了文件夹来将所有下载存储在 linux 服务器文件夹内的 tomcat 路径中: 路径:“opt/tomcat/apache-tomcat-9.0.46/work/downloads/”
当我尝试从外部 API 下载文件到 ubuntu 目录时(以上路径) 我收到外部错误 500,由服务器找不到路径引起。
方法代码:(Java)
@RequestMapping(value = "/downloadDataDump", method = RequestMethod.GET)
public String downloadDataDump(@RequestParam(value = "fileName") String fileName) throws IOException {
String fileUrl = null;
URL url = null;
HttpURLConnection con = null;
try {
fileUrl = getHotelDataDumpUrl("all", "en").getBody().getData().getURL();
url = new URL(fileUrl);
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Accept-Encoding", "zstd");
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
FileOutputStream fout = null;
ZstdInputStream reader = null;
try {
reader = new ZstdInputStream(con.getInputStream());
fout = new FileOutputStream("//212.102.105.18/opt/tomcat/apache-tomcat-9.0.46/work/downloads" + fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
堆栈跟踪(来自评论):
java.io.FileNotFoundException: /opt/tomcat/apache-tomcat-9.0.46/work/downloads/hotelNew (Permission denied)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:126)
at com.hotels.river.controllers.RateHawkController.downloadDataDump(RateHawkController.java:1068)
【问题讨论】:
-
您正在尝试输出到以 IP 地址开头的路径...?
-
UNC 路径仅适用于 Windows,但实际上不需要通过网络传输文件,因为目标文件夹是本地文件夹...
-
目的地不是本地IP地址是外部机器(ubuntu服务器)
-
目的地不是本地的,IP 地址是外部机器(ubuntu 服务器)—— 路径暗示了一个运行在目的地上的 Samba 服务器。有吗?
-
这是最后一次尝试的堆栈跟踪:java.io.FileNotFoundException: /opt/tomcat/apache-tomcat-9.0.46/work/downloads/hotelNew (Permission denied) at java.base /java.io.FileOutputStream.open0(Native Method) at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298) at java.base/java.io.FileOutputStream.
(FileOutputStream.java: 237) 在 java.base/java.io.FileOutputStream. (FileOutputStream.java:126) 在 com.hotels.river.controllers.RateHawkController.downloadDataDump(RateHawkController.java:1068)
标签: java linux file tomcat write