JAVA generates letters and random numbers and files. java generates letters.

Source: Internet
Author: User

JAVA generates letters and random numbers and files. java generates letters.

Package com. ishow. control. code; import java. io. *; import java. text. simpleDateFormat; import java. util. random;/*** @ author Lee * @ version Creation Time: Oct 9, 2015 4:12:25 PM */public class CreateCodeController {/*** generate a redemption Code * @ return * @ throws IOException */public static void main (String [] args) {Long start = System. currentTimeMillis (); String prefix = "LF"; // prefix: int num = 10; // number of digits: int count = 10000; // generate the number of SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH mm"); // generate the File address File f = new File ("C: \ Documents and Settings \ Administrator \ Desktop \ generate code "+ 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 );}}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.