星空网 > 软件开发 > Java

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

package com.ishow.control.code;import java.io.*;import java.text.SimpleDateFormat;import java.util.Random;/** * @author Lee * @version 创建时间:Oct 9, 2015 4:12:25 PM */    public class CreateCodeController{  /**   * 生成兑换码   * @return   * @throws IOException   */  public static void main(String[] args){        Long start = System.currentTimeMillis();        String prefix = "LF";  //前缀     int num = 10;//数字位数     int count = 10000;//生成数量     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH时mm分");        //生成文件地址     File f = new File("C:\\Documents and Settings\\Administrator\\桌面\\生成码" + formatter.format(System.currentTimeMillis()) + ".txt");        OutputStreamWriter writer = null;    BufferedWriter bw = null;        Random random = new Random();    try {      OutputStream os = new FileOutputStream(f);      writer = new OutputStreamWriter(os);      bw = new BufferedWriter(writer);      int i=0;      while(i<count){        String str = "";        for (int j = 0; j < num; j++) {          int number = 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);  }}


 




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

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Lazada物流新升级,为品牌商和商家提供一站式物流服务:https://www.kjdsnews.com/a/570706.html
速卖通西班牙家居销量暴涨260%,怎么做到的?:https://www.kjdsnews.com/a/570707.html
服装LDP条款的硬核干货,有哪些优势?:https://www.kjdsnews.com/a/570708.html
做独立站除了烧钱还有别的方法吗?:https://www.kjdsnews.com/a/570709.html
Facebook广告:Facebook广告的主流类型:https://www.kjdsnews.com/a/570710.html
美国副簿商标对亚马逊备案的影响:https://www.kjdsnews.com/a/570711.html
深圳到西安自驾路线攻略 深圳到西安自驾最佳路线:https://www.vstour.cn/a/411228.html
松花蛋是哪里的特产松花蛋的产地:https://www.vstour.cn/a/411229.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流