package test;

import java.util.Random;
import java.util.UUID;

public class UploadUtils {
	/**
	 * 获取随机名称
	 * 
	 * @param realName
	 *            真实名称
	 * @return uuid
	 */
	public static String getUUIDName(String realName) {
		// realname 可能是 1.jpg 也可能是 1
		// 获取后缀名
		int index = realName.lastIndexOf(".");
		if (index == -1) {
			return UUID.randomUUID().toString().replace("-", "").toUpperCase();
		} else {
			return UUID.randomUUID().toString().replace("-", "").toUpperCase() + realName.substring(index);
		}
	}

	/**
	 * 获取文件真实名称
	 * 
	 * @param name
	 * @return
	 */
	public static String getRealName(String name) {
		// c:/upload/1.jpg 1.jpg
		// 获取最后一个"/"
		int index = name.lastIndexOf("\\");
		return name.substring(index + 1);
	}

	/**
	 * 获取文件目录
	 * 
	 * @param name
	 *            文件名称
	 * @return 目录
	 */
	public static String getDir(String name) {
		int i = name.hashCode();
		String hex = Integer.toHexString(i);
		int j = hex.length();
		for (int k = 0; k < 8 - j; k++) {
			hex = "0" + hex;
		}
		return "/" + hex.charAt(0) + "/" + hex.charAt(1);
	}

	/**
	 * 创建随机文件夹目录
	 * 
	 * @param name
	 *            文件名称
	 * @return 目录
	 */
	public static int getFileName() {
		int max = 100000;
		int min = 10000;
		Random random = new Random();
		
		int s = random.nextInt(max)%(max-min+1) + min;
		return s;
	}
	/**
	 * 随机创建数据库id
	 * 
	 * @param name
	 *            文件名称
	 * @return 目录
	 */
	public static int getSqlId() {
		int max = 100000000;
		int min = 1000000;
		Random random = new Random();
		
		int s = random.nextInt(max)%(max-min+1) + min;
		return s;
	}

	public static void main(String[] args) {

		System.out.println(getSqlId());

	}
}
最近下载更多
朱俪的邮件及存储  LV8 2024年3月11日
linkedwin  LV1 2021年6月30日
xbybjc  LV4 2021年6月30日
陈王子  LV12 2021年5月15日
geekcjj  LV18 2021年1月31日
146zui  LV1 2020年10月31日
王天麟  LV12 2020年9月9日
decisionx1  LV1 2020年6月2日
164317494  LV1 2020年4月14日
eeeerer  LV9 2020年4月12日
最近浏览更多
SZEPEZS  LV9 2月18日
ma406805131  LV19 2024年5月25日
暂无贡献等级
朱俪的邮件及存储  LV8 2024年3月11日
admin_z  LV22 2024年1月29日
ljt289917726  LV3 2023年12月18日
Pro_Guoli 2023年3月23日
暂无贡献等级
12cq345  LV6 2022年11月15日
softandroad 2022年11月8日
暂无贡献等级
heqian  LV17 2022年10月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友