title: Read/Write to an external .txt file using jar file
body: <p>im a newbye and this is my first post. Ive made a game aplication on eclipse that works perfectly. It uses a few .txt files for scores and player options.</p>
  
  <p>The problem is when i try to export it as runnable jar file, well that's the problem, it makes a jar file and makes it impossible for me to write on any of the .txt files i have. I know this because ive tried, well not hundreds but getting close, of solutions and some of which allowed me to read the files but still i cant write on them. I realize this is the normal functioning of a jar file, so my questions are:</p>
  
  <p>How can i have/make an external folder to the jar file in the same directory containing all my txt files? So that it can read and write in those files, and, what methods should i use in my existing code?</p>
  
  <p>Im only showing how i read/write one of those files, but its the same for every other file and im also showing some of the comment on other past solutions:</p>
  
  <pre><code>    private final String cubesScore =  "resF\\score.txt";
      //private final String cubesScore =  "/score.txt";
      //private final String cubesScore =  "//resF//score.txt";
  
      try{
          /*
          try{
              File file = new File(cubesScore);
              //FileReader reader = new FileReader(new File(new File("."), "score.txt"));
  
              if(file.createNewFile()){
                  System.out.println("File created successfully!");
              } else{
                  System.out.println("File already exists.");
              }
  
          } catch(IOException e){
              System.out.println("An error occurred on score.txt!!");
          }
          */
          Scanner scanner = new Scanner(new File(cubesScore));
  
          //InputStream source = this.getClass().getResourceAsStream(cubesScore);
          //Scanner scanner = new Scanner(source);
  
          /*
          InputStream inputStream = this.getClass().getResourceAsStream(cubesScore);
          InputStreamReader inputReader = new InputStreamReader(inputStream);
          BufferedReader reader = new BufferedReader(inputReader);
          */
          int value;
          int i = 0;
          while(scanner.hasNext()){
              value = scanner.nextInt();
              if(value &gt;= 0){
                  mostCubesDestroyed[i] = value;
                  System.out.println(value);
              }
              else 
                  System.out.println("File corrupted");
              ++i;
          }
          scanner.close();
      } catch (NullPointerException | FileNotFoundException e) {
          System.out.println("File Not Found/Null");
      }
  </code></pre>
  
  <p>write:</p>
  
  <pre><code>        try {
               PrintWriter out = new PrintWriter(cubesScore);
               //OutputStream out = this.getClass().getResourceAsStream(cubesScore);
               //out = new PrintWriter(out);
               //BufferedWriter out = new BufferedWriter(new FileWriter(cubesScore));
               //out.write(mostCubesDestroyed[0]);
               //out.newLine();
               out.println(mostCubesDestroyed[0]);
               System.out.println(mostCubesDestroyed[0]+" Cubes GameMode 0");
               //out.write(mostCubesDestroyed[1]);
               //out.newLine();
               out.println(mostCubesDestroyed[1]);
               System.out.println(mostCubesDestroyed[1]+" Cubes GameMode 1");
               //out.write(mostCubesDestroyed[2]);
               //out.newLine();
               out.println(mostCubesDestroyed[2]);
               System.out.println(mostCubesDestroyed[2]+" Cubes GameMode 2");
               //out.write(mostCubesDestroyed[3]);
               //out.newLine();
               out.println(mostCubesDestroyed[3]);
               System.out.println(mostCubesDestroyed[3]+" Total Cubes Destroyed");
               out.close();
            } catch (IOException e) {
                   System.out.println("Error, try again!!");
        }
  </code></pre>
  
  <p>i realize keeping the commented code makes it slightly harder to read but still i wanted to show you some things ive tried...</p>
  
  <p>ive also tried to create the file the first time the app runs but to no success:</p>
  
  <pre><code>      try{
              File file = new File(cubesScore);
              //FileReader reader = new FileReader(new File(new File("."), "score.txt"));
  
              if(file.createNewFile()){
                  System.out.println("File created successfully!");
              } else{
                  System.out.println("File already exists.");
              }
  
          } catch(IOException e){
              System.out.println("An error occurred on score.txt!!");
          }
  </code></pre>
  
  <p>so thats my problem, if anyone been here before and somehow managed to find a solution or you simply know how to produce the desired result, which is to read/write on a .txt file external to the jar(because internal leads to all sorts of issues) then pls tell me what i should do, ive seen more then a hundred post and videos and still couldnt find the desired solution. </p>
  
  <p>Edit: This has been resolved below, turns out i needed a . on "/score.txt" well a . in all files.</p>