title: Get contacts and send to server as a vcf file in android
body: <p>I am trying to convert my contacts to .vcf file in android but it gives an error and can not export contacts.</p>
  
  <p>It gives me an error it goes in the catch block and gives:</p>
  
  <pre><code>java.lang.NegativeArraySizeException: -1
  </code></pre>
  
  <p>I want to export my all contacts to server using vcf file</p>
  
  <pre class="lang-java prettyprint-override"><code>public void getVCF() {
   final String vfile = "Contacts.vcf";
   Cursor phones = mContext.getContentResolver().query(
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
    null, null, null);
   phones.moveToFirst();
   for (int i = 0; i &lt; phones.getCount(); i++) {
    String lookupKey = phones.getString(phones
     .getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
    Uri uri = Uri.withAppendedPath(
     ContactsContract.Contacts.CONTENT_VCARD_URI,
     lookupKey);
    AssetFileDescriptor fd;
    try {
     fd = mContext.getContentResolver().openAssetFileDescriptor(uri, "r");
     FileInputStream fis = fd.createInputStream();
     byte[] buf = new byte[(int) fd.getDeclaredLength()];
     fis.read(buf);
     String VCard = new String(buf);
     String path = Environment.getExternalStorageDirectory()
      .toString() + File.separator + vfile;
     FileOutputStream mFileOutputStream = new FileOutputStream(path,
      true);
     mFileOutputStream.write(VCard.toString().getBytes());
     phones.moveToNext();
     filevcf = new File(path);
     Log.d("Vcard", VCard);
    } catch (Exception e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    }
   }
  }
  </code></pre>