Java 使用apachecommons压缩库进行递归zip文件处理
我一直在尝试使用ApacheCommonsCompress在java中递归访问归档文件,但没有成功 我有一个递归的zip文件,里面的zip可以是任何类型的,比如tar、jar、bz2、gzip等等,也可以是任何深度的 例如:zip->rar->bz2->tarJava 使用apachecommons压缩库进行递归zip文件处理,java,recursion,apache-commons-compress,Java,Recursion,Apache Commons Compress,我一直在尝试使用ApacheCommonsCompress在java中递归访问归档文件,但没有成功 我有一个递归的zip文件,里面的zip可以是任何类型的,比如tar、jar、bz2、gzip等等,也可以是任何深度的 例如:zip->rar->bz2->tar tar->bz2->rar->zip->gzip 下面是我开发的代码 public final class zipLister{ private static final ArchiveStreamFactory factory = ne
tar->bz2->rar->zip->gzip 下面是我开发的代码
public final class zipLister{
private static final ArchiveStreamFactory factory = new ArchiveStreamFactory();
public static void main( String[] args) throws Exception {
File f = new File("three.zip");
processZip(f,Optional.of(""));
}
private static void processZip(File f2, Optional<String> of) throws ArchiveException, IOException {
File f = f2;
String Prefix = f2.getParent();
if (!f.isFile()) {
System.err.println(f + " doesn't exist or is a directory");
}
InputStream fis = new BufferedInputStream(new FileInputStream(f));
ArchiveInputStream ais;
ais = factory.createArchiveInputStream(fis);
System.out.println("Created "+ais.toString());
ArchiveEntry ae;
while((ae=ais.getNextEntry()) != null){
if (ae.getName().endsWith(".xml"))
System.out.println(ae.getName());
else{
processFile(ae,Prefix);
}
ais.close();
fis.close();
}
}
private static void processFile(ArchiveEntry ae2, String fileprefix) throws IOException, ArchiveException {
ArchiveEntry ae;
while ((ae = ((ArchiveInputStream) ae2).getNextEntry()) != null) {
if (ae.getName().endsWith(".xml"))
System.out.println(fileprefix + "\\\\" + ae.getName());
else{
fileprefix = fileprefix + "\\\\" + ae.getName();
processFile(ae,fileprefix);
}
}
}
我无法继续前进。感谢您的帮助
org.apache.commons.compress.archivers.zip.ZipArchiveEntry cannot be cast to org.apache.commons.compress.archivers.ArchiveInputStream