【发布时间】:2019-11-14 07:59:56
【问题描述】:
我想使用运行在Tomcat9上的springboot servlet在这个路径下写一个文件
/mnt/data-new/data/USERPROFILE/607/file.txt
当我尝试写入该文件时,我收到此错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Jul 03 14:11:39 UTC 2019
There was an unexpected error (type=Internal Server Error, status=500).
/mnt/data-new/data/USERPROFILE/607/file.txt (Read-only file system)
我已经使用 777 在该路径上设置了权限,但没有任何改变。
Servlet 代码非常简单:
@GetMapping("/")
public String index() throws IOException {
FileWriter fw = new FileWriter("/mnt/data-new/data/USERPROFILE/607/file.txt");
fw.write("File wrote");
fw.close();
return "OK";
}
我创建了一个名为“file2.txt”的文件,我可以使用此示例代码读取该文件:
@ResponseBody
@GetMapping("/read")
public String read() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("/mnt/data-new/data/USERPROFILE/607/file2.txt"));
String st;
while ((st = br.readLine()) != null) return st;
return null;
}
我以为这是 catalina 政策,但似乎已禁用:
root@devel-spring:/etc/tomcat9# echo $CATALINA_OPTS
-Djava.security.debug=all
而且,即使使用此选项,我在“/var/log/syslog”中也没有安全管理器日志
我应该怎么做才能在那个绝对路径中写入文件?
编辑: 文件系统是 RW 挂载的,我可以使用 bash 创建该文件。
【问题讨论】:
标签: file spring-boot ubuntu io tomcat9