Use Cardme to read and write vcard files for bulk Import Export phone book

Source: Internet
Author: User
Tags vcard

First download the jar package Cardme.

Http://sourceforge.net/projects/cardme/?source=navbar

Cardme is an open source project that operates a vcard (suffix vcf) file based on the Java language.

There is a class Net.sourceforge.cardme.engine.TestParser in the project. It's the official example.

Start by combing a few basic concepts

Vcardengine: used primarily to format or read vcard data from characters, files, and convert to vcard objects .

Vcardwriter: The primary user converts the vcard object to characters for easy writing to the file. It is hard to understand that there is no Vcardreader object. and the Vcardengine object is doing the Vcardreader object thing.

vcard: Can be understood as a business card. Defines the basic Protocol (interface) of the business card.

Vcardimpl: The implementation class of the business card.

Vcardtype: Data for business cards. Business card data are types such as phone teltype, name NameType, address Adrtype


The basic concept is understood. Let's take a look at how to use these APIs

First demand Read

will be used to the Vcardengine class mainly has the following API

Parse: is a method that reads (formats) a vcard object from a file (or character). If the argument is an array, how long does it take to return an array of vcard objects

Parsemultiple: is also an overloaded method. The meaning is to read (format) multiple vcard objects from one file (or character) .

Reading the interface is simple. As long as you understand some of the basic concepts above, there is no problem at all.

Second requirement write

In Testparser, only the vcard object is converted to characters. Did not write to the file, and did not do any example on Vcardtype.

Vcardwriter writer = new Vcardwriter (vcardversion.v3_0, compatibilitymode.rfc2426);//user converts a vcard to a character

FileWriter FW = new FileWriter ("F:/TEL/0.VCF");// Write vcard data (characters) to file

Vcardimpl VC = new Vcardimpl ();//Create a business card

//Set name of business card ( Fntype ). Sets the FN type. This type must is set in the VCard and cannot is omitted, it can however is left with all empty values. The document says this value must be set and cannot be ignored.

VC.SETFN (New Fntype ("Zhang San");

Add a phone number to your business card. A business card can have multiple numbers.

Vc.addtel (New Teltype ("13888888888"));

Writer.setvcard (VC);

String str = writer.buildvcardstring ();//Convert the Business card object to a character

Fw.append (str);//write file

Fw.flush ();

Fw.close ();

the key to vcard is to understand the meaning of its vcardtype. I understand that the data on the card, different data corresponding to the different Vcardtype implementation.



Use Cardme to read and write vcard files for bulk Import Export phone book

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.