简体   繁体   English

在Java中以递归方式在不同文件夹中解压缩多个gzip文件

[英]Unzip multiple gzip files across different folders recursively in Java

I have the following file structure: 我具有以下文件结构:

D:\Files\File1\file.gz, file2.gz, file3.gz
D:\Files\File2\file.gz, file2.gz, file3.gz
etc..

I would like to provide the Java program with just D:\\Files and it should recursively open each directory, and unzip each file.gz and file2.gz (they all have the same name, so I can just ask it to look for all files matching that name) into the same folder. 我想为Java程序提供D:\\Files ,它应该递归地打开每个目录,并解压缩每个file.gz和file2.gz(它们都具有相同的名称,因此我可以要求它查找所有与该名称匹配的文件)放入同一文件夹。

I have tried different codes to get each file to extract but nothing seems to work. 我尝试了不同的代码来提取每个文件,但似乎没有任何效果。 Another funny thing that happens to me is that I can't seem to unlock read-only permissions on the directory. 我发生的另一件有趣的事情是我似乎无法解锁目录的只读权限。 I uncheck it, go to the Security tab and give myself admin privileges, and yet, the next second, its back to read-only. 我取消选中它,转到“安全性”选项卡并为自己赋予管理员特权,但是,下一秒,它又恢复为只读状态。 It's Off topic, but I had to put it out there. 这不是主题,但我不得不把它放在那里。 Please help me someone! 请帮我一个人! Thanks! 谢谢!

Use org.apache.commons.io.FileUtils.iterateFiles using a file filter to specify you only want zip files. 通过文件过滤器使用org.apache.commons.io.FileUtils.iterateFiles来指定您只需要zip文件。

For the decompression use GZIPInputStream. 对于解压缩,请使用GZIPInputStream。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM