如何有效避免文件名相同的问题

将文件名格式设置为时间戳+随机数+文件名的格式

public String setFileName(String oldFileName) {
    /*
     * 时间戳
     */
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
    String time = simpleDateFormat.format(new Date());
    /*
     * 随机数
     */
    Random random = new Random();
    String randomName = String.valueOf(random.nextInt(1000));
    return time+randomName+oldFileName;
}

猜你喜欢

转载自www.cnblogs.com/wyl-yulior-000/p/11224087.html
今日推荐