Problem updating list of data
<pre><code>private static void deleteProxy(File proxyOld, String host, int port) {
        try {
            String lines, tempAdd;
            boolean removeLine = false;
            File proxyNew = new File("proxies_" + "cleaner$tmp");
            BufferedReader fileStream = new BufferedReader(new InputStreamReader(new FileInputStream(proxyOld)));
            BufferedWriter replace = new BufferedWriter(new FileWriter(proxyNew));
            while ((lines = fileStream.readLine()) != null) {
                tempAdd = lines.trim();
                if (lines.trim().equals(host + ":" + port)) {
                    removeLine = true;
                }
                if (!removeLine) {
                    replace.write(tempAdd);
                    replace.newLine();
                }
            }
            fileStream.close();
            replace.close();
            proxyOld.delete();
            proxyNew.renameTo(proxyOld);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
</code></pre>

<p>Calling the function:</p>

<pre><code>File x = new File("proxies.txt");//is calling a new file the reason why it's being flushed out?
deleteProxy(x, host, port);
</code></pre>

<p>Before I run the program the file <code>proxies.txt</code> had data inside of it.  However when I run the program it appears to be flushed out. It becomes empty.</p>

<p>I noticed while the program is running, if I move my mouse over the file <code>proxies.txt</code>, Windows displays the <code>"Date Modified"</code> and the time it displays is the current time, or last time the function <code>deleteProxy(...)</code> was executed.</p>

<p>Does anyone know what I'm doing wrong? And why won't the list update instead of appearing to be empty?</p>

<p>Updated code:</p>

<pre><code>private static void deleteProxy(File proxyOld, String host, int port) {
        try {
            String lines, tempAdd;
            boolean removeLine = false;
            File proxyNew = new File("proxies_" + "cleaner$tmp");
            FileInputStream in = new FileInputStream(proxyOld);
            InputStreamReader read = new InputStreamReader(in);
            BufferedReader fileStream = new BufferedReader(read);
            FileWriter write = new FileWriter(proxyNew);
            BufferedWriter replace = new BufferedWriter(write);

            while ((lines = fileStream.readLine()) != null) {
                tempAdd = lines.trim();
                if (lines.trim().equals(host + ":" + port)) {
                    removeLine = true;
                }
                if (!removeLine) {
                    replace.write(tempAdd);
                    replace.newLine();
                }
            }
            in.close();
            read.close();
            fileStream.close();
            write.close();
            replace.close();

            if (proxyOld.delete()) {
                throw new Exception("Error deleting " + proxyOld);
            }

            if (proxyNew.renameTo(proxyOld)) {
                throw new Exception("Error renaming " + proxyOld);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
</code></pre>

<p>Running the updated code it deletes proxies.txt just fine but it fails to make the new file:\
Maybe I should find a new method to update a text file, do you have any suggestions?</p>
