如何使用 java 创建 vcf 文件?

How to create vcf file using java?

有人可以帮助我吗?如何在 java 中创建 vcard 文件? 它必须包含几个字符串 String name String family name String phone String email

..以及如何为这些属性设置类型,例如 homework 等? 我没有在互联网上找到任何有用的东西,所以我想转向 Whosebug 社区寻求一些建议。

您可以为此使用 Java 库,例如 https://github.com/mangstadt/ez-vcard or you just create a vcard conform String and write it into a File. For information how a vcard looks like see the wiki page http://en.wikipedia.org/wiki/VCard

正在使用 pur 创建 vcf 文件 java。我无意中发现了这个:http://luckyjava.blogspot.de

因为url会失效,这里是源码:

import java.io.*;

public class Vcard
{
 public static void main(String[] args) throws IOException
 {
  File f=new File("contact.vcf");
  FileOutputStream fop=new FileOutputStream(f);

  if(f.exists())
  {
   String str="BEGIN:VCARD\n" + 
     "VERSION:4.0\n" +
     "N:Gump;Forrest;;;\n" +
     "FN:Forrest Gump\n"+
     "ORG:Bubba Gump Shrimp Co.\n"+
     "TITLE:Shrimp Man\n"+
     "TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\n"+
     "TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\n"+
     "EMAIL:forrestgump@example.com\n"+
     "REV:20080424T195243Z\n"+
     "END:VCARD";
   fop.write(str.getBytes());
   //Now read the content of the vCard after writing data into it
   BufferedReader br = null;
   String sCurrentLine;
   br = new BufferedReader(new FileReader("contact.vcf"));
   while ((sCurrentLine = br.readLine()) != null)
   {
    System.out.println(sCurrentLine);
   }
   //close the output stream and buffer reader 
   fop.flush();
   fop.close();
   System.out.println("The data has been written");
  } else 
   System.out.println("This file does not exist");
 }
}