码迷,mamicode.com
首页 > 移动开发 > 详细

生成60w手机号接口,返回下载路径

时间:2020-05-11 11:47:06      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:一个   ext   ppi   下载   buffere   ajax   oba   tst   post   

------------恢复内容开始------------

@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()+"\r\n");
}
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手机号接口,返回下载路径

标签:一个   ext   ppi   下载   buffere   ajax   oba   tst   post   

原文地址:https://www.cnblogs.com/lishuaicq/p/12868016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!