java生成上传图片的唯一ID名称

java生成上传图片的唯一ID名称

徐徐
后端
发布于2024-11-21 14:53:00
🌺前言
java生成上传图片的唯一ID名称

java
public class PathUtils {

    public static String generateFilePath(String fileName){
        //根据日期生成路径   2022/1/15/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/");
        String datePath = sdf.format(new Date());
        //uuid作为文件名
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        //后缀和文件后缀一致
        int index = fileName.lastIndexOf(".");
        // test.jpg -> .jpg
        String fileType = fileName.substring(index);
        return new StringBuilder().append(datePath).append(uuid).append(fileType).toString();
    }
}
文章最后更新于 2024-11-30 17:18:11
留言
暂无数据

~~空空如也