package cn.gov.csrc.util;
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random;
public class RandomUtil {
/** * 生成隨機文件名:當前年月日時分秒+五位隨機數 * * @return */ public static String getRandomFileName() {
SimpleDateFormat simpleDateFormat;
simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
String str = simpleDateFormat.format(date);
Random random = new Random();
int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 獲取5位隨機數
return rannum + str;// 當前時間 }
public static void main(String[] args) {
String fileName = RandomUtil.getRandomFileName();
System.out.println(fileName);//8835920140307 } }