import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import static java.util.Arrays.asList;
public class test01 {
public static void main(String[] args) {
File file = null;
FileWriter fw = null;
file = new File("D:\temp\helloWord.txt");
List<String> area=asList("山西","河南","湖北","北京") ;
List<String> sex=asList("女","男") ;
try {
if (!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(file);
for(int i = 1;i <=1000;i++){
Random r = new Random();
//获取0-9之间的随机数
int number = r.nextInt(4);
int sex01=r.nextInt(2);
fw.write(area.get(number)+","+sex.get(sex01)+","+i+"
");//向文件中写入内容
fw.flush();
}
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fw != null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}