tags:

views:

49

answers:

2

When new data is entered in the GUI and exported to the following file it replaces the existing data, how would i prevent this and make it add to the existing data?

thanks

public void exportContacts()
{
    FileOutputStream file; 
    PrintStream out; 

    try {  file = new FileOutputStream("../files/example.buab");   
           out = new PrintStream(file);       
           out.println(txtname.getText());      
           out.println(txtnum.getText());     
           out.println(txtmob.getText());
           out.println(txtadd1.getText()); 

           System.err.println ("");                    
           out.close();          
        }            
           catch (Exception e)
                 {                   
                  System.err.println ("Error in writing to file");          
                 }
    }
+2  A: 

You should use append mode (javadoc).

tangens
ok thankyou shall try that now
tom1390
+2  A: 
FileOutputStream(String name, boolean append)

so instead of

new FileOutputStream("../files/example.buab");

this:

new FileOutputStream("../files/example.buab", true);
DaMacc
thankyou, it works perfectly now :)
tom1390