package com.hnumi.hadoop.mr;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringJoiner;
public class CreateFile {
public static void main(String[] args) throws IOException {
createFile1("D:\Student.txt");
}
private static void createFile1(String filePath) throws IOException {
String[] names = ("小张,小王,小李,小刘,小陈,小黄,小韩,小董,小宛,小柳").split(",");
File file = new File(filePath);
if (!file.getParentFile().exists()) file.mkdirs();
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
long n = 0;
while (file.length()<1024*1024*10L){
StringJoiner joiner = new StringJoiner("\t");
joiner.add(String.valueOf(n++));
joiner.add(names[getRandom(0,names.length)]);
for (int i = 0;i<5;i++){
if (getRandom(1,10)%5 == 0){
joiner.add(null);
}else {
joiner.add(String.valueOf(getRandom(10,100)));
}
}
}
bw.flush();
bw.close();
}
public static int getRandom(int min,int max){
return (int)(Math.random()*(max-min)+min);
}
}