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/