title: Java PrintWriter - Save File to Source Package in NetBenas
body: <p>I am using the following java code in NetBeans to read and write to a file.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class FileReadWrite {
  
      StringTokenizer tokenizer;
      BufferedReader inFile;
      PrintWriter outFile;
      File myFile;
      private int[] highscores = new int[3];
  
      public FileReadWrite() throws IOException, FileNotFoundException {
  
      }
  
      public int[] ReadFromSave() throws IOException, FileNotFoundException {
  
          inFile = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/files/highscores.txt" )));
          tokenizer = new StringTokenizer(inFile.readLine());
          int i = 0;
          while (tokenizer.hasMoreTokens()) {
              highscores[i] = Integer.parseInt(tokenizer.nextToken());
              i++;
          }
  
          inFile.close();
          return highscores;
  
      }
  
      public void SaveFile(int score) throws IOException, FileNotFoundException {
  
          if (score &gt;= highscores[0]){
              highscores[2] = highscores[1];
              highscores[1] = highscores[0];
              highscores[0] = score;
          }
          else if (score &gt;= highscores[1]){
              highscores[2] = highscores[1];
              highscores[1] = score;
          }
          else if (score &gt;= highscores[2]){
              highscores[2] = score;
          }
  
          PrintWriter outFile = new PrintWriter(new FileWriter("/files/highscores.txt"));
  
          String line = highscores[0] + " " + highscores[1] + " " + highscores[2];
  
          outFile.println(line);
          outFile.close();
  
      }
  
  }
  </code></pre>
  
  <p>I have coded a tetris program and want to save the highscores after each game. And when the user opens up the app next time they are shown the top 3 scores. The ReadFromSave() method started to work fine after I aded "getClass().getResourceAsStream". However I can't get the SaveFile() method working. I gives error "path/file not found". How should I use the PrintWriter in NetBeans so that it saves into the source packages and thus updating the jar. So when the app is fully closed and reopened it has the recent scores printed in. If this is not possible where can I save data so its not lost?</p>
  
  <p>Thank you!!</p>