国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[實例]JAVA生成字母+隨機數字并生成文件

2019-11-14 15:26:19
字體:
來源:轉載
供稿:網友
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);    }}


 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 共和县| 内江市| 隆回县| 句容市| 上林县| 个旧市| 西乡县| 沭阳县| 布拖县| 昌都县| 齐齐哈尔市| 乳源| 行唐县| 武鸣县| 尚义县| 会同县| 德庆县| 乐东| 上高县| 莒南县| 洪泽县| 贵溪市| 玉环县| 海门市| 鸡西市| 房山区| 开江县| 乌兰浩特市| 屏东县| 龙海市| 锡林郭勒盟| 临颍县| 夹江县| 上蔡县| 台南市| 海口市| 佛坪县| 芮城县| 汤阴县| 繁峙县| 高碑店市|