2009-11-29 3 views
1

새 데이터를 GUI에 입력하고 다음 파일로 내 보내면 기존 데이터를 바꿉니다. 어떻게이를 방지하고 기존 데이터에 추가합니까?외부 파일의 기존 데이터를 덮어 씁니다. 어떻게 중지합니까?

감사

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

당신은 추가 모드 (javadoc)를 사용합니다.

+0

확인 감사합니다, 그것은 지금은 완벽하게 작동 지금 – tom1390

3
FileOutputStream(String name, boolean append) 

그래서 대신

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

이 :

new FileOutputStream("../files/example.buab", true); 
+0

고맙다 것을 시도해야한다 : – tom1390

관련 문제