package com.fuyuanshen.web; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class ChineseVCardGenerator { public static void main(String[] args) { // 定义江西上饶的134号段(共22个) String[] prefixes = { "1340703", "1340793", "1342650", "1342651", "1342663", "1342664", "1342665", "1343703", "1343793", "1347901", "1347902", "1347903", "1347930", "1347931", "1347932", "1347933", "1347934", "1347935", "1347936", "1347937", "1347938", "1347939" }; // 创建.vcf文件 String filename = "上饶联系人.vcf"; try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) { // 添加文件头信息(包含中文) writer.write("BEGIN:VCARD"); writer.newLine(); writer.write("VERSION:3.0"); writer.newLine(); writer.write("X-GENERATOR:Java VCard Generator"); writer.newLine(); writer.write("PRODID:-//Apple Inc.//iPhone OS 15.6//EN"); writer.newLine(); writer.newLine(); // 生成所有联系人 int count = 0; for (String prefix : prefixes) { for (int i = 0; i < 100; i++) { String middle = String.format("%02d", i); String phoneNumber = prefix + middle + "51"; // 写入单个联系人(使用中文) writer.write("FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:用户" + (count + 1)); // 中文姓名 writer.newLine(); writer.write("TEL;TYPE=CELL;CHARSET=UTF-8:" + phoneNumber); // 手机号 writer.newLine(); writer.write("NOTE;CHARSET=UTF-8:生成时间 " + new SimpleDateFormat("yyyy-MM-dd").format(new Date())); writer.newLine(); writer.write("END:VCARD"); writer.newLine(); writer.newLine(); count++; } } System.out.println("成功生成 " + count + " 个中文联系人"); System.out.println("文件已保存为: " + filename); } catch (IOException e) { System.err.println("文件写入错误: " + e.getMessage()); } } }