用程序生成 急啊 在线等 谢谢。

解决方案 »

  1.   

    package com.sigurd.test;import java.util.Random;/**
     * @author janson_chang
     * @date 2007-3-7
     * @todo 随即生成中文
     */
    public class UnicodeTest { /**
     * @param args
     */
    public static void main(String[] args) {
    System.out.println(new String(getCh(getChs(8))));

    System.out.println(getChs(8));
    }
    /**
     * 
     * @param len 传入长度
     * @return String
     */
    private static String getChs(int len) {
    StringBuffer str = new StringBuffer();
    String rBase = new String("0123456789abcdef");
    for (int i = 0; i < len; i++) {
    Random rnd = new Random();
    int f1, f2, f3, f4;
    f1 = rnd.nextInt(2) + 11;
    if (f1 == 13) {
    f2 = rnd.nextInt(7) + 8;
    } else {
    f2 = rnd.nextInt(6) + 9;
    }
    f3 = rnd.nextInt(6) + 10;
    if (f3 == 10) {
    f4 = rnd.nextInt(14) + 1;
    } else if (f3 == 15) {
    f4 = rnd.nextInt(14);
    } else {
    f4 = rnd.nextInt(15);
    }
    str.append(rBase.substring(f1, f1 + 1) + rBase.substring(f2, f2 + 1)
    + rBase.substring(f3, f3 + 1) + rBase.substring(f4, f4 + 1));
    }
    System.out.println(str.toString());
    return str.toString();
    }
    /**
     * 
     * @param s 传入的字节字符串转换为中文字节数组
     * @return byte[]
     */
    private static byte[] getCh(String s) {
    byte[] data = new byte[s.length() / 2];
    int j = 0;
    int temp = 0;
    for (int i = 0; i < s.length(); i++) {
    temp = Integer.parseInt(s.substring(i, i + 1), 16);
    temp = temp << 4;
    i++;
    temp = temp + Integer.parseInt(s.substring(i, i + 1), 16);
    data[j] = (byte) temp;
    j++;
    }
    return data;
    }
    }