title: Generate a file next to the jar file containing the code
body: <p>I have a jar with my application that should create a file next to it. So in folder I will have this : </p>
  
  <p><code>Source 
   |_ MyApplication.jar
   |_ generatedFile.txt
  </code></p>
  
  <p>Easy thing I thought... nope.. I am lost... I have a code like this: </p>
  
  <pre><code>URL location = MyClass.class.getProtectionDomain().getCodeSource().getLocation();
          String path = location.getFile().substring(0, location.getFile().lastIndexOf("/MyContext"));
          File file = new File(fileName + ".txt");
          File file1 = new File(path + "/MyFileName.txt");
          File file2 = new File(path.substring(1) + "/MyFileName.txt");
  </code></pre>
  
  <p>I tried different combinations, googled alot and I am lost... if I get for example</p>
  
  <pre><code>file1.getPath();
  file2.getAbsolutePath();
  </code></pre>
  
  <p>and so on, the paths are correct... but the file isn't generated... Only working case is the first one, but that is located inside the jar and I don't want that. </p>
  
  <p>I also tried to moving the existing file outside using </p>
  
  <pre><code>Paths.move(...
  </code></pre>
  
  <p>but that hasn't helped me at all.. </p>
  
  <p>Can someone help me with this ? And explain to me why isn't the examples above working ? Thanks.. </p>