Creating and replacing new files with same title
<p>I have an existing text file. However, I want to overwrite the file, this includes deleting some words in the file. Therefore I think it would be easier if I write the data into a file with the same name and hope that the previous file will be overwrite, but this is not true. How can I do that?</p>

<pre><code>JFileChooser chooser = new JFileChooser();
int status = chooser.showOpenDialog(null);

if(status ==JFileChooser.APPROVE_OPTION) {
    File f = chooser.getSelectedFile();

    PrintWriter(new FileOutputStream(f.getName()));
</code></pre>