简体   繁体   English

用Java提取存档文件

[英]Extracting Archive Files in Java

I am looking for a library to extract archive files with. 我正在寻找一个用于提取存档文件的库。 For example, zips, rars, tars, wars, ... 例如,zips,rars,tars,wars,...

My application so far only supports .ZIP's & .RAR's, but I want to increase support for several other archive types. 到目前为止,我的应用程序仅支持.ZIP和.RAR,但我想增加对其他几种归档类型的支持。 Not only that, but I want the library to "detect" archive files, even if I give them another extension or no extension at all. 不仅如此,即使我给它们另一个扩展名或根本没有扩展名,我也希望库“检测”存档文件。

Basically, I'm looking for some sort of interface to which I can pass a file and path, which then checks if the file is an archive file, returns an error if it's not, and extracts the files to the specified path if it is. 基本上,我正在寻找某种接口,我可以将文件和路径传递到该接口,然后检查文件是否为存档文件,如果不是则返回错误,如果是则将文件提取到指定路径。 I'm guessing that there are different implementations for different filetypes, but it would be very useful if the library detects this, and automatically passes it on to the right implementation. 我猜想对于不同的文件类型有不同的实现,但是如果库检测到它并自动将其传递给正确的实现,那将非常有用。

You could use Apache Commons Compress . 您可以使用Apache Commons Compress

This library is also used by the great Apache Tika which can be used to detect different file formats also with no extension (but maybe the huge Apache Tika is an overkill for your task). 出色的Apache Tika也使用了该库,该Apache Tika也可用于检测不同的文件格式,并且没有扩展名(但庞大的Apache Tika可能对您的任务有些大材小用)。

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

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