title: Java: getCodeBase() on non-applet application
body: <p>I'm trying to create a URL to access a local file like so:</p>
  
  <pre><code>URL myURL = new URL(getCodeBase(), "somefile.txt");
  </code></pre>
  
  <p>But it throws a NullPointerException when it attempts getCodeBase(). I'm fairly certain that the reason behind this is because the class file that this code belongs to is not an applet. Is there any way I can get the code base without using an applet? I just want to access a local file without having to put the actual directory in (because when others run the application the directory path will obviously not be the same).</p>