我正在做一个电话簿,我想将联系人保存到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:[email protected]\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

关于java - 如何在Java中使用自己的数据创建vcard?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55943902/

10-12 06:02