如何在 Java 中使用自己的数据创建 vcard?
How to create vcard with own datas in Java?
我正在制作电话簿,我想将联系人保存到 vcard。我在网上找到了 vcard 格式,但我不知道如何从 stdin 读取数据。
package homework;
import java.io.*;
public class SaveToVcard {
public static void vcard() throws IOException {
File file = new File("contact.vcf");
FileOutputStream fop = new FileOutputStream(file);
if (file.exists()) {
String vcard = "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(vcard.getBytes());
BufferedReader br = null;
String currentLine;
br = new BufferedReader(new FileReader("contact.vcf"));
while ((currentLine = br.readLine()) != null) {
System.out.println(currentLine);
}
fop.flush();
fop.close();
System.out.println("Kész");
} else
System.out.println("A fájl nem létezik");
}
您可以使用扫描仪并执行类似这样的操作
Scanner sc = new Scanner(System.in);
String input = sc.next();
见https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html
或者您可以在 运行 您的应用程序
时将需要的内容作为参数传递
见https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
我正在制作电话簿,我想将联系人保存到 vcard。我在网上找到了 vcard 格式,但我不知道如何从 stdin 读取数据。
package homework;
import java.io.*;
public class SaveToVcard {
public static void vcard() throws IOException {
File file = new File("contact.vcf");
FileOutputStream fop = new FileOutputStream(file);
if (file.exists()) {
String vcard = "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(vcard.getBytes());
BufferedReader br = null;
String currentLine;
br = new BufferedReader(new FileReader("contact.vcf"));
while ((currentLine = br.readLine()) != null) {
System.out.println(currentLine);
}
fop.flush();
fop.close();
System.out.println("Kész");
} else
System.out.println("A fájl nem létezik");
}
您可以使用扫描仪并执行类似这样的操作
Scanner sc = new Scanner(System.in);
String input = sc.next();
见https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html
或者您可以在 运行 您的应用程序
时将需要的内容作为参数传递见https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html