Recently, when generating files, random file names need to be generated according to the date, which is hereby recorded for future reference.

package com.openailab.oascloud.file.util;

import com.openailab.oascloud.file.common.consts.BootstrapConst;

import java.text.SimpleDateFormat;
import java.util.Date;

/ * * *@description: File tool *@author: zhangzhixiang
 * @createDate: 2020/1/7
 * @version: 1.0 * /
public class FileUtil {
    /** * Randomly generate file names based on the date **@param ext
     * @return java.lang.String
     * @author zxzhang
     * @date2019/10/8 * /
    public static String createFileName(String ext) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        return simpleDateFormat.format(new Date()) + (int) (Math.random() * 900 + 100) + BootstrapConst.SPOT + (ext == null ? "": ext); }}Copy the code

The Java language completes the introduction to generating random file names based on dates.