packagecom.ishow.control.code;importjava.io.*;importjava.text.SimpleDateFormat;importjava.util.Random;/***@authorLee
*@version创建时间:Oct 9, 2015 4:12:25 PM*/publicclassCreateCodeController{/*** 生成兑换码
*@return*@throwsIOException*/publicstaticvoidmain(String[] args){
Long start=System.currentTimeMillis();
StringPRefix= "LF";//前缀intnum = 10;//数字位数intcount = 10000;//生成数量SimpleDateFormat formatter=newSimpleDateFormat("yyyy-MM-dd HH时mm分");//生成文件地址File f =newFile("C:\\Documents and Settings\\Administrator\\桌面\\生成码" + formatter.format(System.currentTimeMillis()) + ".txt");
OutputStreamWriter writer=null;
BufferedWriter bw=null;
Random random=newRandom();try{
OutputStream os=newFileOutputStream(f);
writer=newOutputStreamWriter(os);
bw=newBufferedWriter(writer);inti=0;while(i<count){
String str= "";for(intj = 0; j < num; j++) {intnumber = random.nextInt(10);
str+=number+"";
}
str= prefix+str;try{
bw.write(str+"\r\n");
}catch(Exception e) {
i--;
}
i++;
}
bw.flush();
}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}finally{try{
bw.close();
}catch(IOException e) {
e.printStackTrace();
}
}
Long end=System.currentTimeMillis();
System.out.println("bufferedWrite And FileWriterTest's time---------" + (start - end)/1000d);
}
}