使用 Cardme Java 创建 VCard

发布于 2024-11-04 00:51:50 字数 1166 浏览 1 评论 0原文

你好 我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城已无爱 2024-11-11 00:51:50

您需要导入正确的输出类:

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();
    }   
    }

You need to import the proper output class:

import info.ineighborhood.cardme.io.VCardWriter;

Or in latest versión of the library (v0.3.3) the package is:

import net.sourceforge.cardme.io.VCardWriter; 

and then use it:

/**
     *  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();
    }   
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文