[实例]JAVA生成字母+随机数字并生成文件

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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);

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航