title: reading and writing to same file with jar
body: <p>So, here's the problem: I'm working on a Java program that reads from a .csv file, and constructs objects out of it.  I'm using InputStream, InputStreamReader, and BufferedReader to read the file. The IDE I'm using is NetBeans and the file being read is in the src directory.  A quick note, for your convenience, I hardcoded the filename, so that you would understand how it's actually being read. In my actual program, the filename is being passed in as a parameter of the method. Anyways, it seems to work fine in the IDE.  But when I create a JAR, it doesn't do what I want it to do.</p>
  
  <pre><code>    public void readFile(filename) throws IOException, FileNotFoundException {
  
                  is = getClass().getResourceAsStream("file.csv"); 
                  isr = new InputStreamReader(is);
                  //fr = new FileReader(filename);
                  br = new BufferedReader(isr);
                  String info;
  
          while ((info = br.readLine()) != null)
           {
                          String[] tokens = info.split(",");
                          Object object = new Object();
                          object.setProperty(tokens[0]);
                          object.setAnotherProperty(tokens[1]);
                          object.setSomeOtherProperty(tokens[2]);
           }
  
           } 
  catch (FileNotFoundException f) 
      {
          f.getMessage();
      } 
  catch (IOException ioe)
       {
          ioe.getMessage();
       } 
  catch (ArrayIndexOutOfBoundsException oob)
       {
          //;
       } 
  catch (NullPointerException npe)
       {
          //;
       }
  finally
       {
          br.close();
          isr.close();
          is.close();
       }
  </code></pre>
  
  <p>My method to update the file looks like this(once again, the filename has been hardcoded so you could better understand what's going on):</p>
  
  <pre><code>public void updateRoom(String filename, String property1, string property2, string property3) throws FileNotFoundException
  </code></pre>
  
  <p>{</p>
  
  <pre><code>        for (Objects o : objects)
          {
              if (o.getProperty().equals(property1))
              {
                  o.setProperty(property1);
                  o.setAnotherProperty(property2);
                  o.setSomeOtherProperty(property3);
              }
          }
  
          File file = new File("file.csv");
          PrintWriter pr = new PrintWriter(file);
          for (Object o : objects)
          {
  
              pr.println(o.getProperty() + "," +
                         o.getAnotherProperty() + "," +
                         o.getSomeOtherProperty())
          }
          pr.close();
   }
  </code></pre>
  
  <p>The problem is that the .JAR reads the file when I run it, but instead of writing to the SAME file, it simply creates a new one and writes to that one.  It's a problem because every time I run the program again, the properties and values remain unchanged.  It's NOT reading from the newly-created file.  It's still reading from the original file, but it's writing to a new file.</p>
  
  <p>I want to READ AND WRITE to the same file. That way, if I close the program and run it again, it will have the new properties/values already loaded in.  </p>