title: Saving files in current directory
body: <p>I've been searching for this and many answers came out but it just wasn't the solution I was looking for so I came here and try to ask help to you guys...</p>
  
  <p>I want to create a <code>.txt</code> file in the same folder where the JAR file is located  (dist folder)...</p>
  
  <p>I tried using <code>System.getProperty("user.dir")</code> it works fine when I run it on windows and using netbeans the file created is always in the same folder where the jar file is but when I run it on LINUX it saves the file in root... but the folder where the jar file is on the desktop</p>
  
  <p>it creates in the same folder when I use the terminal to open the jar file</p>
  
  <pre><code>private static String directory=System.getProperty("user.dir");
  private final String sample=directory+File.separator+"sample.txt";
  
  
  public void createFile()
  {
       File file=new File(sample);
      try(FileWriter fw=new FileWriter(file))
      {
          fw.write("INSERT ME WHERE MY JAR IS");
          fw.flush();
          fw.close();
      }catch(IOException ex)
      {
          ex.printStackTrace();
      }
  }
  </code></pre>