Skip to content

Instantly share code, notes, and snippets.

@otw1248
Last active April 22, 2016 08:41
Show Gist options
  • Save otw1248/a34f89f3d72f0c18a2d6 to your computer and use it in GitHub Desktop.
Save otw1248/a34f89f3d72f0c18a2d6 to your computer and use it in GitHub Desktop.
java;source code;

#####search a file in jar files by name

static void checking(String fileName, String jarPath) {
        File jarsFolder = new File(jarPath);
        File jar = null;
        JarEntry jarEntry = null;
        String jarEntryName = "";
        try {
            if (jarsFolder != null && jarsFolder.isDirectory()) {
                File[] jars = jarsFolder.listFiles();
                if (jars != null && jars.length > 0) {
                    for (int i = 0; i < jars.length; i++) {
                        jar = jars[i];
                        JarFile jarFile = new JarFile(jar);
                        if (jarFile != null) {
                            Enumeration<JarEntry> jarEntryEnumeration = jarFile.entries();
                            if (jarEntryEnumeration != null) {
                                while (jarEntryEnumeration.hasMoreElements()) {
                                    jarEntry = jarEntryEnumeration.nextElement();
                                    jarEntryName = jarEntry.getName();
                                    if (jarEntryName.indexOf(fileName) > 1) {
                                        System.out.println("jar Name:" + jar.getName()
                                                + "; jarEntry:" + jarEntry.getName());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment