导包
import org.apache.commons.lang3.RandomStringUtils;
代码
// 0-9a-zA-z 参数为字符数量 RandomStringUtils.randomAlphanumeric(1); // 汉字 Random random = new Random(); Integer highPos = 176 + Math.abs(random.nextInt(39)); Integer lowPos = 161 + Math.abs(random.nextInt(93)); byte[] b = new byte[] {highPos.byteValue(), lowPos.byteValue()}; try { String str = new String(b, "GB2312"); System.out.println(str); } catch (UnsupportedEncodingException e) { log.error(" 获取中文汉字 异常 :", e); }