【#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推荐阅读
- #yyds干货盘点#golang判断一个网段是否属于另一个网段的子网
- ansible——playbook的模块
- windows服务查看进程命令
- 苹果电脑Mac系统日常快捷键
- 主从复制及主主复制的实现
- 城市天然气地下泄漏监测系统软件方案
- 警卫应急仿真模拟训练系统软件方案
- xtrabackup实现全量+增量+binlog恢复库
- 部署Tomcat负载均衡 #yyds干货盘点#