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生成字母+随机数字并生成文件的更多相关文章

  1. Sql自动生成字母加数字的随机数

    /* select char(65+ceiling(rand()*25)) --随机字母(大写) select char(97+ceiling(rand()*25)) --随机字母(小写) selec ...

  2. 在javaweb的项目当中实现随机数字的生成

    首先,需要在javaweb的项目当中新建一个Servlet文件,然后再web.xml中配置一下: 这样运行的时候就可以通过“http://localhost:8080/Response/Respons ...

  3. Python Random模块生成伪随机数字

    This module implements pseudo-random number generators for various distributions. 对于整数,有一个范围的均匀选择: 对 ...

  4. ios 生成字母加数字的随机数

    文章来自:http://blog.csdn.net/baidu_25743639/article/details/73801700 近期项目第三方登录之后默认创建账号和密码,就用随机数生产,这里只需要 ...

  5. c#随机生成汉字、字母、数字

    /// <summary> /// 替换变量 /// </summary> /// <param name="content"></par ...

  6. Java——Random类随机整数---18.10.11

    一.Random类的定义 1.Random类位于java.util包中,主要用于生成 伪随机数 2.random类将 种子数 作为随机算法的起源数字,计算生成伪随机数,其与生成的随机数字的区间无关 3 ...

  7. Java基础之随机生成数字和字母

    字母与数字的ASCII码 目 前计算机中用得最广泛的 字符集及其编码,是由美国国家标准局(ANSI)制定的ASCII码(American Standard Code for Information I ...

  8. 随机生成长度为len的密码,且包括大写、小写英文字母和数字

    一道华三面试题,随机生成长度为len的密码,且包括大写.小写英文字母和数字,主要Random类的使用,random.nextInt(len)表示生成[0,len)整数.具体实现见下面代码,已经很详细了 ...

  9. [转]java生成随机数字和字母组合

    摘自 http://blog.csdn.net/xiayaxin/article/details/5355851 import java.util.Random; public String getC ...

随机推荐

  1. python云算法

    http://www.runoob.com/python3/python3-basic-operators.html 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中, ...

  2. [学习OpenCV攻略][011][显示图片]

    学习资料: http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/tutorials.html   包含头文件 core.hpp:包含 ...

  3. insertBefore方法(javascript与jQuery)

    说到insertBefore()方法,其实javascript与jQuery中都有此方法,那么他们用法是否相同呢? 其实,还是有点区别的.反正我是爱搞混淆了,先做个小笔记吧! 1.insertBefo ...

  4. Hive HQL学习

    HQL学习   1.hive的数据类型 2.hive_DDL 2.1创建.删除.修改.使用数据库     Default数据库,默认的,优先级相对于其他数据库是最高的   2.2重点:创建表_内部表_ ...

  5. 织梦DedeCMS v5.7 实现导航条下拉菜单

    首先将下面这段代码贴到templets\default\footer.htm文件里(只要在此文件里就行,位置无所谓) <</span>script type='text/javasc ...

  6. vue前后台数据交互vue-resource文档

    地址:https://segmentfault.com/a/1190000007087934 Vue可以构建一个完全不依赖后端服务的应用,同时也可以与服务端进行数据交互来同步界面的动态更新. Vue通 ...

  7. telnet配置和telnet用法

    搭建或配置网络环境时,经常会使用ping命令检查网络是否可达.有些时候Ping命令也不好使,比如因防火墙禁止或访问策略限制等.则可使用telnet测试映射端口或远程访问主机. Telnet协议是TCP ...

  8. Thrift之TProtocol系列TBinaryProtocol解析

    首先看一下Thrift的整体架构,如下图: 如图所示,黄色部分是用户实现的业务逻辑,褐色部分是根据thrift定义的服务接口描述文件生成的客户端和服务器端代码框架(前篇2中已分析了thrift ser ...

  9. gRPC实战

    gRPC是Google开源的一款非常棒的系统间通信工具,完美的communication抽象,构建在protobuf之上的RPC. 下面我们聊聊它的应用场景,grpc为分布式系统而生,可以是系统间通信 ...

  10. socket 编程--sockaddr与sockaddr_in区别与联系(转)

    在linux环境下,结构体struct sockaddr在/usr/include/linux/socket.h中定义,具体如下:typedef unsigned short sa_family_t; ...