title: Problem saving contacts in text file using string
body: <p>This My Code for Save Contact in external storage directory. But this code is a problem when I open the Contact.txt file on my phone, the last phone number stored on the phone is recorded in the Contact.txt file.</p>
  
  <pre><code>private void getContactList() {
          ContentResolver cr = getContentResolver();
          Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                  null, null, null, null);
          String phoneNo = null;
  
          if ((cur != null ? cur.getCount() : 0) &gt; 0) {
              while (cur != null &amp;&amp; cur.moveToNext()) {
  
                  String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                  String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
  
                  if (cur.getInt(cur.getColumnIndex(
                          ContactsContract.Contacts.HAS_PHONE_NUMBER)) &gt; 0) {
                      Cursor pCur = cr.query(
                              ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                              null,
                              ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                              new String[]{id}, null);
                      while (pCur.moveToNext()) {
                          phoneNo = pCur.getString(pCur.getColumnIndex(
                                  ContactsContract.CommonDataKinds.Phone.NUMBER));
                          Log.i("TAG", "Name: " + name);
                          Log.i("TAG", "Phone Number: " + phoneNo);
                      }
                      pCur.close();
  
                      File root = new File(Environment.getExternalStorageDirectory(), "cache");
  
                      if (!root.exists())
                          root.mkdirs();
  
                      try {
                          File fileContact = new File(root, "Contact.txt");
                          FileWriter writer = new FileWriter(fileContact);
                          writer.append("Name: " + name + " - " + "Phone Number: " + phoneNo);
                          writer.flush();
                          writer.close();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
  
  
                      Log.i("TAG", "Game Over.");
                  }
              }
          }
          if (cur != null) {
              cur.close();
          }
      }
  </code></pre>