java - 需要从 Java JSP 运行递归触摸的帮助

标签 java unix command execute

Java中有没有办法使用exec方法来执行递归操作?

目标是设置一个简单的网页,重新加载时将触及该网站的目录,以便设计可以保证不再发生缓存。请帮忙!!!

这是我到目前为止所拥有的,但没有在我的 jsp 中工作:

<%@ page import="java.io.BufferedReader,java.io.File,java.io.FileWriter, java.io.IOException, java.io.InputStreamReader, java.util.Map" %>

<%


String s = null;
// system command to run
String cmd = "find /home/abcdefg/ -exec touch {} \\;";
// set the working directory for the OS command processor
File workDir = new File("/home/ss/public_html/ss");

try {
Process p = Runtime.getRuntime().exec(cmd, null, workDir);
int i = p.waitFor();
if (i == 0){
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
}
else {
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((s = stdErr.readLine()) != null) {
System.out.println(s);
}

}
}
catch (Exception e) {
System.out.println(e);
}


%>

最佳答案

您真的要触摸 /home/abcdefg 下的文件吗?我可以想象您想要触摸 /home/ss/public_html/ss 下的所有文件。如果是这种情况,您必须更改 find 命令:

String cmd = "find /home/ss/public_html/ss -exec touch {} \\;"

关于java - 需要从 Java JSP 运行递归触摸的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5865141/

相关文章:

java - 判断java中的当前时间是否超过预定时间15分钟

java - 在 imageview JavaFx 上显示图像

linux - 使用sed删除文件中的行

java - 如何忽略两个文件中的注释变化和空行变化?

c - 你如何处理未知数量的命令行参数?

WPF : InputBindings on a StackPanel

C程序改变目录

java - Elasticsearch-忽略持久化的属性

Java new Thread 使用这个 - 有什么理由它是好/坏吗?

linux - Echo -e 在我的脚本中不起作用