您好我正在尝试使用 Cardme API 在 Java 中创建一个 vcard (.vcf) 文件。我可以保存一个 .vcf 文件,但它没有内容并且是空的。请在下面找到我的代码,
private void generateVCard(Card card){
HelperClass helper = new HelperClass();
VCardImpl vcard = new VCardImpl();
BeginFeature begin = new BeginFeatureImpl();
vcard.setBegin(begin);
vcard.addEmail(helper.formEmailFeature(card));
vcard.addAddress(helper.formAddress(card));
vcard.addPhoto(helper.formPhotoFeature(card));
vcard.addTelephoneNumber(helper.formTelephoneFeature(card));
vcard.setName(helper.formNameFeature(card));
vcard.setFormattedName(helper.formattedName(card));
saveToFile("vc.vcf",vcard);
}
/**
* This function saves a VCard to disk.
*/
public void saveToFile( String fileName , VCard vcard) {
Writer output = null;
File file = new File("fileName");
try {
output = new BufferedWriter(new FileWriter(file));
output.write(vcard.toString());
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
感谢解决此问题的任何帮助。