我正在尝试使用 Java Runtime 类压缩和存档文件夹中的所有文件。我的代码片段如下所示:
public static void compressFileRuntime() throws IOException, InterruptedException {
String date = Util.getDateAsString("yyyy-MM-dd");
Runtime rt = Runtime.getRuntime();
String archivedFile = "myuserData"+date+".tar.bz2";
String command = "tar --remove-files -cjvf "+archivedFile+" marketData*";
File f = new File("/home/amit/Documents/");
Process pr = rt.exec(command, null, f);
System.out.println("Exit value: "+pr.exitValue());
}
上面的代码没有按预期归档和压缩文件,尽管它myuserData2009-11-18.tar.bz2
在文件夹“ /home/amit/Documents/
”中创建了一个文件。
输出也是
Exit value: 2.
如果我从命令行执行相同的命令,它会给出预期的结果。
请告诉我我错过了什么。
谢谢阿米特
_