Dynamically update text file in Java GUI
<p>I have created JAVA GUI that will receive text file(.txt) from other client and append into the textarea(by using TextRecv.append) in Java Netbeans GUI however it doesn't read file that already sent from other client , I try to put readfile method in button perform however it read only when I push the button but that's not the result that I want, my target is make this GUI to dynamically receive file , read and append on to my text area automatically </p>

<p>My situation is I have 2 Machine and then I send file by execute dtncpd in Java that's process how I send file over 2 machines however in both 2 machine the text file is already appear in destination but It not append in the textarea </p>

<p>That's how I send</p>

<pre><code> private void DTNSendActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    String text = "";
    String name = usernameField.getText();
    text = name.toString()+ ":"+ TextInput.getText().toString();

    try{
        FileWriter fstream = new FileWriter("msg.txt");
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(text);
        out.close();
    }catch(IOException e)
    {
        e.printStackTrace();
    }
    TextInput.setText("");


    try{ //Show what sender type
        BufferedReader ins = new BufferedReader(new FileReader("msg.txt"));
        String Stream;
        while((Stream = ins.readLine())!=null)
        {
            TextRecv.append(Stream+"\n");
        }
    }catch(IOException e){ e.printStackTrace();}

    String sendcmd = "dtncp NetBeansProjects/DTNChat/msg.txt dtn://abc.dtn";
    Runtime runtime1 = Runtime.getRuntime();
    try{
        Process process1 =runtime1.exec(sendcmd);
    }catch(IOException e)
    {
        e.printStackTrace();
    }
</code></pre>

<p>The question is how can the Java Gui read the file that receive and append to the textarea automatically without using any button</p>

<p>Any Suggestion?? Thank you for every advice</p>

<p><strong>Edited</strong>
I'm coding like this however it's not append on my TextArea</p>

<pre><code> SwingWorker worker = new SwingWorker&lt;Void,String&gt;(){
    protected Void doInBackground(){
        File file = new File("/home/XXX/Desktop/incoming/ABC.dtn/msg.txt");
        boolean exists = file.exists();
        while(exists)
        {
            try{
                FileReader read = new FileReader("/home/XXX/Desktop/incoming/ABC.dtn/msg.txt");
                BufferedReader in = new BufferedReader(read);
                String show;
                while((show=in.readLine())!=null)
                {
                    TextRecv.append(show);
                }
            }catch(IOException e){}
        }
        return null;
    }
};

    public void actionPerformed(ActionEvent ae){
        worker.execute();
    }
</code></pre>
