生成60w手机号接口,返回下载路径
Posted lishuaicq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成60w手机号接口,返回下载路径相关的知识,希望对你有一定的参考价值。
------------恢复内容开始------------
@PostMapping("/exportTwo")
@ResponseBody
public AjaxResult exportTwo()
{
String downloadPath="";
try {
FileOutputStream fileOutputStream=null;
BufferedWriter bufferedWriter=null;
downloadPath = Global.getDownloadPath() + UUID.randomUUID()+".txt";
File desc = new File(downloadPath);
if (!desc.getParentFile().exists())
{
desc.getParentFile().mkdirs();
}
bufferedWriter = new BufferedWriter(new FileWriter(downloadPath));
for (int i = 0; i < 600000; i++) {
bufferedWriter.write(generatePhoneNum()+" ");
}
bufferedWriter.close();
fileOutputStream.close();
}catch (Exception e){
}
return AjaxResult.success(downloadPath);
}
public String generatePhoneNum() {
//匹配国内手机号的正则(注意: js中d前面只有一个‘’ ,java的是两个“”)
String s = "^((1[3|8][0-9])|(14[5|7])|(15([0-3]|[5-9])|(16[5|6]))|(17[0-8])|(19[8|9]))\d{8}$";
Pattern r = Pattern.compile(s);
String phoneNum = "";
Matcher matcher = r.matcher(phoneNum);
do {
phoneNum = autoGenerate();
matcher = r.matcher(phoneNum);
} while (matcher.matches() != true);
return phoneNum;
}
private String autoGenerate() {
Random random = new Random();
StringBuffer buffer = new StringBuffer();
buffer.append("1");
for (int i = 0; i < 10; i++) {
int num = random.nextInt(10);
buffer.append(num);
}
return buffer.toString();
}
------------恢复内容结束------------
以上是关于生成60w手机号接口,返回下载路径的主要内容,如果未能解决你的问题,请参考以下文章