简体   繁体   English

如何使用java程序将文本文件压缩为rar格式

[英]How to compress text file to rar format using java program

Is there any java library by which we can compress a plain text file(.txt) into winRAR format(.rar). 是否有任何java库可以将纯文本文件(.txt)压缩为winRAR格式(.rar)。 I have been searching in google but couldn't find any relevant library which does that. 我一直在谷歌搜索,但找不到任何相关的库,这样做。

你可以随时做

Runtime.getRuntime().exec("rar -a somefile.txt"); 

I think RAR is not open-source format. 我认为RAR不是开源格式。 I'd rather use ZIP - it's built-in in Java. 我宁愿使用ZIP - 它内置于Java中。

RAR is a proprietary format, and I don't know of any library to create it (although there seem to be some that can read it). RAR是一种专有格式,我不知道要创建它的任何库(虽然似乎有一些可以读取它)。 Any reason why you wouldn't use another, more open format like 7zip (for compression), or plain Zip (for universal compatibility)? 你之所以不使用其他更开放的格式,如7zip (压缩)或普通Zip (用于通用兼容性)?

(From the question, of which this one is a duplicate - RAR archives with java ) (从问题来看,这个是重复的 - RAR使用java存档

You could try JUnRar, "a RAR handling API implemented in pure Java" (quoting the site). 您可以尝试JUnRar,“在纯Java中实现的RAR处理API”(引用该站点)。

No you can not do it. 不,你做不到。 Only WinRAR can create rar file. 只有WinRAR才能创建rar文件。 There is only a unrar library for it. 它只有一个unrar库。

One reason to use RAR: It is sooooo much better than ZIP. 使用RAR的一个原因是:它比ZIP好得多。 For example: One of our production print files has a lot of repetition (including images) in it. 例如:我们的一个生产打印文件中有很多重复(包括图像)。 142 MB large, it zips to about 80MB. 142 MB大,它拉到大约80MB。 RAR seems to detect these repetitions and the resulting file is not even 2MB! RAR似乎检测到这些重复,结果文件甚至不是2MB!

Why RAR? 为何选择RAR? as others have mentioned, RAR is not open. 正如其他人所说,RAR不公开。

Java has native ZIP API. Java具有原生ZIP API。 Java Zip API: How to Create a Zip File Using Java Java Zip API:如何使用Java创建Zip文件

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

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