标签:一个 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();
}
------------恢复内容结束------------
标签:一个 ext ppi 下载 buffere ajax oba tst post
原文地址:https://www.cnblogs.com/lishuaicq/p/12868016.html