Command line 解压没有它的所有文件';使用Java创建文件夹

Command line 解压没有它的所有文件';使用Java创建文件夹,command-line,java,zip,rar,Command Line,Java,Zip,Rar,是否可以从zip文件夹中解压所有文件而不使用其文件夹 示例: String sevenZipLocation = "C:\\Program Files\\7-Zip\\7z.exe"; String src = source filepath (zip file) String target = output path (output path) String[] command={sevenZipLocation,"x",src,"-o"+target,"-aou","-y"}; Proc

是否可以从zip文件夹中解压所有文件而不使用其文件夹

示例:

String sevenZipLocation = "C:\\Program Files\\7-Zip\\7z.exe";
String src = source filepath (zip file)
String target = output path (output path)

String[] command={sevenZipLocation,"x",src,"-o"+target,"-aou","-y"};

ProcessBuilder p = new ProcessBuilder( command );
Process process = p.start();

InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

@SuppressWarnings("unused")
String line;

while ((line = br.readLine()) != null){
    System.out.println("line1 "+line);
}
process.waitFor();
zipfolder.zip有两个子文件夹,分别称为folder1(具有1.txt、2.xlsx、3.pdf等文件)和folder2(具有4.txt、5.pdf等文件)

注意:源文件可以是任何类型的存档文件,如.zip、.rar、.tar、.7-zip等

这是我的代码:

String sevenZipLocation = "C:\\Program Files\\7-Zip\\7z.exe";
String src = source filepath (zip file)
String target = output path (output path)

String[] command={sevenZipLocation,"x",src,"-o"+target,"-aou","-y"};

ProcessBuilder p = new ProcessBuilder( command );
Process process = p.start();

InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

@SuppressWarnings("unused")
String line;

while ((line = br.readLine()) != null){
    System.out.println("line1 "+line);
}
process.waitFor();
当我执行此代码时,输出如下

解压文件夹------folder1(具有类似于1.txt、2.xlsx、3.pdf的文件)和folder2(具有类似于4.txt、5.pdf的文件)

但是我想从所有文件夹中提取唯一的文件,然后像这样输出 输出路径中的1.txt、2.xlsx、3.pdf、4.txt、5.pdf


有什么命令吗。谢谢。

您需要更改的全部内容:

String[] command={sevenZipLocation,"e",src,"-o"+target,"-aou","-y","*.*","-r"};

另外,我不认为Java是运行OS命令的最佳选择。你会浪费很多时间。但是如果您坚持,请不要忘记也可能有错误流。

运行“7z--help”并查看它是否有“e”命令“extract without directory”。这些将对您有所帮助。您不需要运行CMD命令。上面的链接只能提取zip文件,而不能提取.rar、.tar、.7-zip文件。上面的答案还包括子文件夹,如何消除文件夹创建。它正在工作。非常感谢。