title: Searching all files of the parent file (and all other files within the parent file) JAVA
body: <p>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).</p>
  
  <p>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)</p>
  
  <p>I currently have this:</p>
  
  <pre><code>    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);
          }
      }
  }
  </code></pre>
  
  <p>And this is what I use to try and get the parent file:</p>
  
  <pre><code>        File directory = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
      main.searchForClasses(directory);
  </code></pre>
  
  <p>Does anyone have any ideas on what I can switch?</p>