尝试在 HD 上写入文件时出现“(只读文件系统)”

I get "(Read-only file system)" when try to write a file on HD

我想使用在 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.

创建该文件

感谢 Debian 中的 Emmanuel Bourg bugs.debian.org link 我发现 Tomcat9

"is sandboxed to write only into its own directory. You'll have to tweak the systemd configuration to allow Tomcat to write into ..." [that] "... directory".

所以我 nano'd /etc/systemd/system/multi-user.target.wants/tomcat9.service 添加

ReadWritePaths=/mnt/data-new/data/

然后

systemctl daemon-reload
service tomcat9 restart

现在,

通过上面的代码,我成功地编写了我的测试文件。