我尝试了一个简单的程序来在运行时执行 Linux 命令。但是下面的程序被编译并运行没有任何错误,但是文本文件没有按预期创建。这个程序有什么问题吗?
import java.io.*;
class ExecuteJava
{
public static void main(String args[])
{
String historycmd = "cat ~/.bash_history >> Documents/history.txt";
try
{
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec(historycmd);
}
catch(Exception e)
{
System.out.println(e);
}
}
}