我有一个代码可以将一个 ZIP 文件存档到另一个 ZIP 文件中,使用如下命令:
String rootftp = "C:\\ROOT_DIR_PUSHFILE\\";
String tampungString = "AAA\\PFILE\\AAA20140531.zip";
String password = "testing";
String command = "cmd.exe "
+ "/C"
+ " cd C:\\Program Files\\WinRAR \n"
+" && rar a -n "+rootftp.trim()+tampungString+".zip"+" "+ rootftp.trim()+tampungString + " -p"+password.trim();
System.out.println(command);
File file = new File(rootftp.trim()+tampungString);
try {
Runtime.getRuntime().exec(command);
file.delete();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
但结果是:
当我尝试归档特定文件时,结果始终是从根目录归档,而不仅仅是特定文件,例如 AAA20140531.zip 文件,您能解释一下吗?为什么?又该如何解决呢?
最佳答案
使用此命令创建没有父文件夹的.rar
:
rar a -ep1 c:\ROOT_DIR_PUSHFILE\AAA\PFILE\AAA20140531.zip c:\ROOT_DIR_PUSHFILE\AAA\PFILE\ -p123456
-ep1
开关使结果从路径中排除基本文件夹,
关于java - 针对特定文件的 WinRAR 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31096175/