I need a java library to read vcard files (vcf).
-
2Stackoverflow is a web site for QUESTIONS. Please rephrase it as a question. Nonetheless, it's not a real question. – guerda Mar 23 '09 at 09:43
8 Answers
ez-vcard supports versions 2.1, 3.0, and 4.0 of the vCard standard, as well as XML-encoded vCards ("xCard" standard), HTML-encoded vCards ("hCard" microformat), and JSON-encoded vCards ("jCard" standard).
https://github.com/mangstadt/ez-vcard
To read a vCard file, use the Ezvcard.parse()
method. Then, call the various getter methods on the returned VCard
object to retrieve the vCard data fields.
File file = new File("my-vcard.vcf");
VCard vcard = Ezvcard.parse(file).first();
System.out.println("Name: " + vcard.getFormattedName().getValue());
System.out.println("Email: " + vcard.getEmails().get(0).getValue());

- 34,873
- 17
- 75
- 109
-
Hey, seems like best .vcf parser so far, but lets say I have .vcf that has email home, email work and email other. Can you please show detailed example of how would I store different types of emails (home, other, work) to String emailHome, emailWork, emailOther? vcard.getEmails().get(0).getValue(); always gives first, but how to know if that is home email or work email or other email? – Marko Niciforovic Jul 01 '13 at 15:20
-
1@Marko Call the "getTypes()" method on each email object to get its list of "type" parameters. You can then check to see if its type is "home" or "work": email.getTypes().contains(EmailTypeParameter.HOME); – Michael Jul 02 '13 at 11:41
-
3
A search for Java and vcard yields quite a few results.
In particular there's the Mime-Dir-j which is no longer under active development, but may be all you need, and vcard4j which seems to have been dormant for even longer (last release 2003!).

- 1,421,763
- 867
- 9,128
- 9,194
-
I already found those projects and was hoping for something else in active development, but I'll try them anyway, thank you all. – Giorgio Gelardi Mar 23 '09 at 15:57
-
1As a quick FYI, Mime-Dir-j seems to include the vcard4j code but also has more recent bug fixes applied. – Luke Quinane Mar 10 '11 at 03:07
Cardme seems to be the best vcard library around with active development and there is even a wiki site up.
Check the project homepage.

- 130
- 8

- 81
- 1
- 1
I found this API that might do the trick: http://sourceforge.net/projects/mime-dir-j/

- 18,670
- 17
- 71
- 81
Well, just in case you want to use a mobile phone, JSR75 does it right out of the box:
javax.microedition.pim.PIM.fromSerialFormat is specified as supporting vCard 3.0

- 6,836
- 1
- 16
- 32