我确实通过Tomcat apache将用spring编写的java web应用程序部署到ubuntu linux服务器上。我创建了一个文件夹来存储linux服务器文件夹中tomcat路径下的所有下载:文件名:“opt/tomcat/apache-tomcat-9.0.46/work/downloads/“(文件名:opt/tomcat/apache-tomcat-9.0.46/work/downloads/apache-tomcat-9.0.46),文件名:”文件名:“文件名:”
当我尝试从外部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)
1条答案
按热度按时间vwkv1x7d1#
您有权限问题:
java
进程的用户tomcat
):要创建文件,Tomcat需要对所有目录的遍历(
x
)权限和对downloads
文件夹的写入(w
)权限。