2016-08-02 7 views
0

このコードはオブジェクトの一部であり、各オブジェクトはその場所をaccountstorage.txtに書き込む必要がありますが、appendをtrueに設定しても書き込み時にFileOutputStream(ファイル、追加)が付加されない

accountstorage = new File(currDir + "/Clients/accountstorage.txt"); 

     try { 
      if(!accountstorage.exists()) { 
     accountstorage.getParentFile().mkdirs(); 
     accountstorage.createNewFile(); 
      } else { 
       return; 
      } 


      fos = new FileOutputStream(accountstorage, true); 
      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); 


     bw.write("@" + accountfile.getParentFile() + "\r\n"); 
     bw.flush(); 
     bw.close(); 

何が原因ですか?私は自分自身で問題を見つけることができないようです。そのため、あなたの条件ブロックの

答えて

1

if(!accountstorage.exists()) { 
    accountstorage.getParentFile().mkdirs(); 
    accountstorage.createNewFile(); 
} else { 
    return; // DUE to this... Remove else block to fix. 
} 

あなたのファイルは、それを作成した場所が、あなたのファイルは、それが返され、何も書かない存在次回の書き込みが存在しません。

これが役に立ちます。

+0

ありがとう、私はそれを見落とした! –

+0

あなたを助けてくれてうれしい:) – Sanjeev

関連する問題