[实例]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生成字母+随机数字并生成文件的更多相关文章
- Sql自动生成字母加数字的随机数
/* select char(65+ceiling(rand()*25)) --随机字母(大写) select char(97+ceiling(rand()*25)) --随机字母(小写) selec ...
- 在javaweb的项目当中实现随机数字的生成
首先,需要在javaweb的项目当中新建一个Servlet文件,然后再web.xml中配置一下: 这样运行的时候就可以通过“http://localhost:8080/Response/Respons ...
- Python Random模块生成伪随机数字
This module implements pseudo-random number generators for various distributions. 对于整数,有一个范围的均匀选择: 对 ...
- ios 生成字母加数字的随机数
文章来自:http://blog.csdn.net/baidu_25743639/article/details/73801700 近期项目第三方登录之后默认创建账号和密码,就用随机数生产,这里只需要 ...
- c#随机生成汉字、字母、数字
/// <summary> /// 替换变量 /// </summary> /// <param name="content"></par ...
- Java——Random类随机整数---18.10.11
一.Random类的定义 1.Random类位于java.util包中,主要用于生成 伪随机数 2.random类将 种子数 作为随机算法的起源数字,计算生成伪随机数,其与生成的随机数字的区间无关 3 ...
- Java基础之随机生成数字和字母
字母与数字的ASCII码 目 前计算机中用得最广泛的 字符集及其编码,是由美国国家标准局(ANSI)制定的ASCII码(American Standard Code for Information I ...
- 随机生成长度为len的密码,且包括大写、小写英文字母和数字
一道华三面试题,随机生成长度为len的密码,且包括大写.小写英文字母和数字,主要Random类的使用,random.nextInt(len)表示生成[0,len)整数.具体实现见下面代码,已经很详细了 ...
- [转]java生成随机数字和字母组合
摘自 http://blog.csdn.net/xiayaxin/article/details/5355851 import java.util.Random; public String getC ...
随机推荐
- 多文件中的static
这里借鉴一篇文章:http://www.cnblogs.com/yc_sunniwell/archive/2010/07/14/1777431.html#undefined 在这里举个例子,先和你说说 ...
- light oj 1152 Hiding Gold
题目: You are given a 2D board where in some cells there are gold. You want to fill the board with 2 x ...
- error: Failed dependencies:解决
error: Failed dependencies:解决 使用rpma安装安装包时,会出现 error: Failed dependencies: 意思是 失败的依赖 解决方法: 在安装包后面加两个 ...
- 如何在外部终止一个pengding的promise对象
今天在整理前段时间做过的项目,发现之前在集成web环信的时候遇到过一个奇怪的需求:需要终止一个正在进行等待返回的promise,或者阻止其调用resolve和reject.(具体为何会有这种需求我也不 ...
- 如何把域名解析到网站空间IP上?
建立网站首要就是要有一个域名和网站空间,怎么把这两者联系在一起呢?这就要通过域名解析,把域名指向空间的IP,让我们能够通过域名访问网站空间.通过域名解析把我们容易记住的域名转化成IP地址,由DNS服务 ...
- 引导图滤波(Guided Image Filtering)原理以及OpenCV实现
引导图是一种自适应权重滤波器,能够在平滑图像的同时起到保持边界的作用,具体公式推导请查阅原文献<Guided Image Filtering>.这里只说一下自适应权重原理.C++实现灰度图 ...
- __block __weak
IOS BLOCK收集 在ios,blocks是对象,它封装了一段代码,这段代码可以在任何时候执行.Blocks可以作为函数参数或者函数的返回值,而其本身又可以带输入参数或返回值.它和传统的函数指针很 ...
- vue学习笔记(四)——Vue实例以及生命周期
1.Vue实例API 1.构造器(实例化) var vm = new Vue({ //选项 |-------DOM(3) | |-------el (提供一个在页面上已存在的 DOM 元素作为 V ...
- SSH的jar包下载地址
spring http://repo.spring.io/libs-release-local/org/springframework/spring/ 条理清晰的搭建SSH环境之添加所需jar包 ht ...
- 2017-07-06(grep man apropos )
grep 格式 grep [选项] 字符串 文件名 选项 -i 忽略大小写 -v 排除指定字符串 作用 在文件中查找字符串 例子 grep "size" anaconda- ...