Compressing & Decompressing 7z file in java
27,178
Solution 1
I have used : sevenzipjbinding.jar sevenzipjbinding-Allplatforms.jar
I am now able to decompress files using these jars.
Try this link for decompression: http://sourceforge.net/projects/sevenzipjbind/forums/forum/757964/topic/3844899
Solution 2
SevenZipBinding is great for decompression, it even detects format automaticaly. Problem is it can't compress. You can create zip archives using ZIP4J. It however offers only plain zip. LZMA apparently can compress single files into 7z archives, but I haven't tried it yet.
Related videos on Youtube
Author by
user1728310
Updated on August 05, 2022Comments
-
user1728310 almost 2 years
I want to compress a file into zip, rar and 7z format using java code. Also I want to decompress these files at a specified location. Can anyone please tell me how to compress and decompress files using 7-zip in java?
-
David Schwartz over 11 yearsDid you try punching
7zip java
into a search engine? You would have found hits like 7-Zip-JBinding. -
user1728310 over 11 yearsI have tried it but I could only get the list of files.
-
David Schwartz over 11 yearsGo to this page. There's a link right at the top if you want the Windows version.
-
user1728310 over 11 yearsThanks David I used these jars: sevenzipjbinding.jar sevenzipjbinding-Allplatforms.jar But I think they can be used only for the extraction of compressed file. Is there any way to compress files using 7-zip?
-
Code-Apprentice over 11 years@user1728310 Since you have tried so many things, would you mind telling us what you have tried?
-
user1728310 over 11 yearsAs i told earlier, I have used sevenzipjbinding.jar sevenzipjbinding-Allplatforms.jar and I am able to decompress files using these jars.
-
user1728310 over 11 yearsYou can get the code for de-compression from following link : sourceforge.net/projects/sevenzipjbind/forums/forum/757964/…
-
matbrgz about 11 years@DavidSchwartz a binding means native code. That may not be an option in a pure Java environment.
-
Vadzim about 6 yearsPossible duplicate of How to use LZMA SDK to compress/decompress in Java
-
-
Olathe almost 11 yearsYou either mean a bash script, which won't work very often on Windows, or a batch script, which won't work very often off Windows. There are even systems which have Java but no scripting at all, like some mobile phones.
-
Thakhani Tharage almost 11 yearsHi Olate the assumption was that the code will be running on windows so i meant batch script. The question did not specify as to whether it will run on Linux or windows. For u to say it wont work is absolutely ridicule as i have done this before. String cmd = "cmd /c " + [7Zip APP] + " x " + [ARCHIVE] + " -o" + [Destination]; Process process = Runtime.getRuntime().exec(cmd.toString()); 7 zip provide a app that u can use to extract and compress. Voting down my answer??? . This works perfectly on windows
-
Olathe almost 11 yearsIt doesn't necessarily work perfectly on Windows. The user has to install the 7-Zip software without error in order to make it work, which is quite a hassle, particularly if the user is not at all good with computers (which is made even more difficult if they also don't have administrative rights; will they even know that the shell search path exists so they can set it up properly?). More importantly, there are much easier multiplatform solutions that don't require the installation of any additional software and that will work on Linux web servers and Android as well, where Java is used a lot.
-
Thakhani Tharage almost 11 yearsThe questions never specified the platform, i am glad there is a platform independent jar. Though it was not necessary to vote down this solution as it works within the context of the question