Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to decompress jar

Shulou Source: shulou.com Published: 2022-06-02 02:24:53 11月04日 Update

This article introduces you how to decompress jar, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Scene

Upload the jar package on the page

Extract the jar package in the background

The page shows all the package

Select a package

The page displays class and sub-package

Select class to go to the class parsing page

Select package to display class and sub-package

Decompress jarpackage com.wuxiongwei.java.jar2;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.nio.ByteBuffer;import java.nio.channels.Channels;import java.nio.channels.FileChannel;import java.nio.channels.ReadableByteChannel;import java.util.Enumeration;import java.util.jar.JarEntry;import java.util.jar.JarFile / * very good tool class

* decompress jar. * @ author * @ version 1.0.0 * / public class JarDecompression {protected static Log log = LogFactory.getLog (JarDecompression.class); @ SuppressWarnings ("resource") public static void uncompress (File jarFile, File tarDir) throws IOException {JarFile jfInst = new JarFile (jarFile); Enumeration enumEntry = jfInst.entries (); while (enumEntry.hasMoreElements ()) {JarEntry jarEntry = (JarEntry) enumEntry.nextElement () File tarFile = new File (tarDir, jarEntry.getName ()); if (jarEntry.getName (). Contains ("META-INF")) {File miFile = new File (tarDir, "META-INF"); if (! miFile.exists ()) {miFile.mkdirs ();}} makeFile (jarEntry, tarFile) If (jarEntry.isDirectory ()) {continue;} FileChannel fileChannel = new FileOutputStream (tarFile). GetChannel (); InputStream ins = jfInst.getInputStream (jarEntry); transferStream (ins, fileChannel) }} / * Stream switching operation * @ param ins input stream * @ param channel output stream * / private static void transferStream (InputStream ins, FileChannel channel) {ByteBuffer byteBuffer = ByteBuffer.allocate (1024 * 10); ReadableByteChannel rbcInst = Channels.newChannel (ins) Try {while (- 1! = (rbcInst.read (byteBuffer) {byteBuffer.flip (); channel.write (byteBuffer); byteBuffer.clear ();}} catch (IOException ioe) {ioe.printStackTrace () } finally {if (null! = rbcInst) {try {rbcInst.close ();} catch (IOException e) {e.printStackTrace () }} if (null! = channel) {try {channel.close ();} catch (IOException e) {e.printStackTrace () }} / * print jar file content information * @ param file jar file * / public static void printJarEntry (File file) {JarFile jfInst = null;; try {jfInst = new JarFile (file);} catch (IOException e) {e.printStackTrace () } Enumeration enumEntry = jfInst.entries (); while (enumEntry.hasMoreElements ()) {log.info ((enumEntry.nextElement () }} / * create file * @ param jarEntry jar entity * @ param fileInst file entity * @ throws IOException throws an exception * / public static void makeFile (JarEntry jarEntry, File fileInst) {if (! fileInst.exists ()) {if (jarEntry.isDirectory ()) {fileInst.mkdirs () } else {try {fileInst.createNewFile ();} catch (IOException e) {log.error ("failed to create file >" .concat (fileInst.getPath () }} public static void main (String [] args) {File jarFile = new File ("/ Users/mac/Documents/other/bw2/bopsdk-openapi-1.0.2-Release.jar"); File targetDir = new File ("/ Users/mac/Documents/other/bw2/test/"); try {JarDecompression.uncompress (jarFile, targetDir) } catch (IOException e) {e.printStackTrace ();} this is the end of sharing about how to decompress jar. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Files pages content selections entities more help good information interests background scenes guys partners tools articles knowledge articles references input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Xiaomi Microsoft Apple vpn