Extracting .jar file with command line

后端 未结 8 799
悲哀的现实
悲哀的现实 2020-12-04 07:52

I am trying to extract the files from a .jar file. How do I do that using command line?

I am running Windows 7

8条回答
  •  悲哀的现实
    2020-12-04 08:39

    Java has a class specifically for zip files and one even more specifically for Jar Files.

    java.util.jar.JarOutputStream
    java.util.jar.JarInputStream
    

    using those you could, on a command from the console, using a scanner set to system.in

    Scanner console = new Scanner(System.in);
    String input = console.nextLine();
    

    then get all the components and write them as a file.

    JarEntry JE = null;
    while((JE = getNextJarEntry()) != null)
    {
        //do stuff with JE
    }
    

    You can also use java.util.zip.ZipInputStream instead, as seeing a JAR file is in the same format as a ZIP file, ZipInputStream will be able to handle the Jar file, in fact JarInputStream actually extends ZipInputStream.

    an alternative is also instead of getNextJarEntry, to use getNextEntry

提交回复
热议问题