你好
我正在尝试使用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();
}
}
感谢您解决此问题的任何帮助.
解决方法:
您需要导入适当的输出类:
import info.ineighborhood.cardme.io.VCardWriter;
或在该库的最新版本(v0.3.3)中,该软件包是:
import net.sourceforge.cardme.io.VCardWriter;
然后使用它:
/**
* This function saves a VCard to disk.
*/
public static void saveToFile( String fileName , VCard vcard) {
Writer output = null;
File file = new File("fileName");
try {
output = new BufferedWriter(new FileWriter(file));
VCardWriter writer = new VCardWriter();
writer.setVCard(vcard);
output.write(writer.buildVCardString());
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
标签:vcard,java
来源: https://codeday.me/bug/20191208/2091702.html