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

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

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;
}

 

posted @ 2019-07-22 09:48  Yulior  阅读(284)  评论(0编辑  收藏  举报