Reading and writing jar files using java

Hi Friends ,

I’m back with another interesting tutorial , today i’ll telling how to read a jar file and write the jar file to destination folder.

You can also say copying jar file from one location to another /destination location.

So first find the code below :

So now what i’m doing is reading the “sourceLocation” checking whether its a file if yes calling my method to copy that file to “destinationLocation” else if its folder i’m going inside the folder scanning for jar file and calling the method passing that file as argument.

So in the method “copyJarFile” takes two argument the source jar file and other the destination folder where the source file must be copied here we are using the

JarOutputStream jos = new JarOutputStream(new FileOutputStream(destFile));

JarOutputStream for taking jar file as inputstream


Enumeration<JarEntry> entries = jarFile.entries();

inorder get the entries inside it and writing jos.

So using while loop all entries are written and then we are closing stream and flushing out .


Feel free to comment for any doubts , also if you like it please share as sharing is caring 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.