title: How to overwrite existing file?
body: <p>I want to overwriting file that I have saved before, my <code>saveAs</code> code:</p>
  <pre><code>public void saveAs(){
              judul = jTextJudul.getText();
              s = area.getText();
              if(s.length()&gt;0){//jika s terisi
                  try { 
                      dialog = new FileDialog(this,&quot;Save File As&quot;,FileDialog.SAVE);
                      dialog.setFile(judul+&quot;.txt&quot;);
                      dialog.setVisible(true);
                      path=dialog.getDirectory()+dialog.getFile();
                      FileOutputStream fos=new FileOutputStream(path);
                      System.out.println(s);
                      byte[] b=s.getBytes();
                      fos.write(b);
                      fos.close();
                      setTitle(name);
                  }
                  catch(Exception e){
                      JOptionPane.showMessageDialog(this,e.getMessage());
                  }
              }
              else{
                  JOptionPane.showMessageDialog(this,&quot;Apa anda yakin menyimpan file kosong?&quot;);
              }
          }
  </code></pre>
  <p>And my save code (that must be overwriting exist file)</p>
  <pre><code>public void Save(){
          dialog = new FileDialog(this,&quot;Save&quot;,FileDialog.SAVE);
          file = new File(path+&quot;.txt&quot;);
          s = area.getText();
            try{
              // Create file 
              FileWriter fstream = new FileWriter(file,true);
              BufferedWriter out = new BufferedWriter(fstream);
              out.write(s);
              //Close the output stream
              out.close();
          }
          catch (IOException e){
              JOptionPane.showMessageDialog(this,e.getMessage());
          }
      }
  </code></pre>
  <p>But when I save, the file will saved to &quot;null.txt&quot;</p>
  <p>This is not what I want. I would like to overwrite the file that i have saved before.</p>