gpt4 book ai didi

java - ProcessBuilder 在文件确实存在时给出 "File not found"异常

转载 作者:搜寻专家 更新时间:2023-10-31 08:15:21 25 4
gpt4 key购买 nike

<分区>

正在处理将在 Linux Web 服务器上运行的应用程序以从特定目录中删除日志,但是我不断收到 FileNotFound 异常。

代码如下:

public static void deleteLOG() {
try {
ProcessBuilder probuilder = new ProcessBuilder("find /home/root/multicraft/servers/ -name '*.log' -delete");
probuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}

还有异常(exception)

java.io.IOException: Cannot run program "find . -name '*CoreData*' -delete" (in directory "/home/root/multicraft/servers"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(Unknown Source)
at com.mcprohosting.com.nodecleanup.Preprocess.deleteCoreData(Preprocess.java:23)
at com.mcprohosting.com.nodecleanup.handlers.CleanupHandler.executeCleanup(CleanupHandler.java:36)
at com.mcprohosting.com.main.NodeCleaner.init(NodeCleaner.java:29)
at com.mcprohosting.com.main.NodeCleaner.main(NodeCleaner.java:25)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more

但是命令 cd/home/root/multicraft/servers 工作得很好。

我也试过:

    ProcessBuilder probuilder = new ProcessBuilder("find . -name '*Backup*' -delete");
probuilder.directory(new File("/home/root/multicraft/servers/"));
probuilder.start();

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com