I am trying to get the parent folder of my jar, and search all the way through it. The reason being is that I am modifying all of the .class files beneath the jar on the build path (there are a bunch of jars below it).
I am currently getting an NPE on dir.listFiles() in the searchForClasses method, the reason being is that when I am creating a new instance of file, it is not the correct path. (I believe)
I currently have this:
public void searchForClasses(File dir) {
for (File f : dir.listFiles()) {
if (f.getName().endsWith(".class")) {
for (byte[] bytes : NMSversions)
fix(f.getAbsolutePath(), bytes, NMS);
for (byte[] bytes : OBCversions)
fix(f.getAbsolutePath(), bytes, OBC);
System.out.println("fixing");
} else {
searchForClasses(f);
}
}
}
And this is what I use to try and get the parent file:
File directory = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
main.searchForClasses(directory);
Does anyone have any ideas on what I can switch?