#yyds干货盘点#golang生成vcf格式文件详解

【#yyds干货盘点#golang生成vcf格式文件详解】亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述#yyds干货盘点#golang生成vcf格式文件详解相关的知识,希望能为你提供帮助。
1.何为vcf文件
?VCF是通讯录格式文件,一般需要用手机通讯录导入导出的文件格式都是vcf格式。?
?2.生成文件的目的是啥?
?如果你是卖房销售,或者你是做什么推销的,你可以生成同城的手机号,一个个打电话推销。?
?3.源码?

package number


/*
@Time : 2021/12/22 17:44
@Author :dengfeng_hu
@File : phone
@Software: GoLand
*/



import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
)

const (
inputFilePath = "D:/phone.txt"
fileName = "洛阳"
last = "36"
fileSize = 5
outputPath = "D://phoneNumber"
)

func getNum(fileName string) int
var num = 1
for
if _,err:=os.Stat("D://phoneNumber/" + fileName + strconv.Itoa(num)+".vcf");
os.IsNotExist(err)
return num

num++




func Exe()
mid := read()
for i:=0; i< len(mid); i=i+5
var subList []string
if i+fileSize< len(mid)
subList = mid[i:i+fileSize:len(mid)]
else
subList = mid[i:len(mid):len(mid)]

fmt.Println(subList)
MyTest(subList,fileName,last)



func MyTest(mid []string,fileName string,last string)
num := getNum(fileName)
file, err := os.OpenFile(outputPath+"/" + fileName +strconv.Itoa(num) +".vcf", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil
fmt.Println("文件打开失败", err)
return

//及时关闭file句柄
defer file.Close()
write := bufio.NewWriter(file)
count:=1
for i := 0; i< len(mid); i++
for j := 0; j< 100; j++
phoneNumber := strings.ReplaceAll(mid[i],"\\r\\n","") + fmt.Sprintf("%02d", j) + last
makeNumber(phoneNumber,write,strconv.Itoa(count))
count++


makeNumber("15804299051",write,strconv.Itoa(count))
write.Flush()
fmt.Println("文件创建成功,时间:"+time.Now().Format("2006-01-02 15:04:05"))



func makeNumber(num string,w *bufio.Writer,index string)
w.WriteString("BEGIN:VCARD" + "\\r\\n")
w.WriteString("VERSION:3.0" + "\\r\\n")
w.WriteString("FN; CHARSET=UTF-8:1" + "\\r\\n")
w.WriteString("N; CHARSET=UTF-8:; ; " + "A"+index +"; ; " + "\\r\\n")
w.WriteString("TEL; TYPE=CELL:" + num+ "\\r\\n")
w.WriteString("END:VCARD" + "\\r\\n")



func read() []string
var mid []string
f, err := os.Open(inputFilePath)
if err != nil
panic(err)

defer f.Close()
rd := bufio.NewReader(f)
for
line, err := rd.ReadString(\\n) //以\\n为结束符读入一行
if err != nil

    推荐阅读