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 🙂