Home > Mobile >  How to copy a JarEntry to a directory
How to copy a JarEntry to a directory

Time:04-19

I have scanned the maven directory (.m2) and have filtered all the files ending with .jar.

List<File> jarFiles = scanRecursivelyForJarObjects(mavenRepository, fileManager);

I am trying the copy the .class files inside the JarFile to a different directory. Here is the code:

for(File jarFile : jarFiles) {
        Enumeration<JarEntry> enumeration = new JarFile(jarFile).entries();
        while (enumeration.hasMoreElements()) {
            JarEntry jarEntry = enumeration.nextElement();
            if (!jarEntry.isDirectory() && jarEntry.getName().endsWith(".class")) {
                copyFile(new FileInputStream(jarEntry), classesDir.getAbsolutePath()   "\\"   jarEntry.getName());
            }
        }
    }

But it is throwing an error when I try to copy because jarEntry is not a File.

I am not sure how to convert jarEntry to a File.

CodePudding user response:

You can get the input stream to the entry.

new JarFile(file).getInputStream(jarEntry)

CodePudding user response:

IOUtils.copyStream(jarEntry.getInputStream(), new FileOutputStream(new File(classesDir.getAbsolutePath(), jarEntry.getName())));
  • Related