使用 Cardme Java 创建 VCard
你好 我正在尝试使用 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();
}
}
感谢解决此问题的任何帮助。
Hi
I am trying to create a vcard (.vcf) file in Java using Cardme API.
I can save a .vcf file, but it has no contents in it and empty.
Please find my code below,
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();
}
}
Appreciate any help in resolving this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要导入正确的输出类:
或者在库的最新版本(v0.3.3)中,包是:
然后使用它:
You need to import the proper output class:
Or in latest versión of the library (v0.3.3) the package is:
and then use it: