How to unzip files recursively in Java?

后端 未结 9 2060
慢半拍i
慢半拍i 2020-11-27 03:10

I have zip file which contains some other zip files.

For example, the mail file is abc.zip and it contains xyz.zip, class1.java

9条回答
  •  死守一世寂寞
    2020-11-27 03:25

    File dir = new File("BASE DIRECTORY PATH");
    FileFilter ff = new FileFilter() {
    
        @Override
        public boolean accept(File f) {
            //only want zip files
            return (f.isFile() && f.getName().toLowerCase().endsWith(".zip"));
        }
    };
    
    File[] list = null;
    while ((list = dir.listFiles(ff)).length > 0) {
        File file1 = list[0];
        //TODO unzip the file to the base directory
    }
    

提交回复
热议问题