Skip to content

Instantly share code, notes, and snippets.

@TheMasteredPanda
Created December 17, 2016 16:03
Show Gist options
  • Save TheMasteredPanda/da29f6de0b5c7ab0666b7d535cff8df6 to your computer and use it in GitHub Desktop.
Save TheMasteredPanda/da29f6de0b5c7ab0666b7d535cff8df6 to your computer and use it in GitHub Desktop.
Lerning how to get classes && packages from other jars
package me.tmp.jar2;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Main
{
public static void main(String[] args)
{
List<String> classNames = new ArrayList<String>();
try {
ZipInputStream zip = new ZipInputStream(new FileInputStream("C:/Users/kingo/Desktop/jar1.jar"));
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
if (!entry.isDirectory()) {
String className = entry.getName().replace('/', '.');
classNames.add(className.substring(0, className.length()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
for (String s : classNames) {
if (s.contains("t2.txt")) {
System.out.println("Found t2.txt");
}
System.out.println(s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment