String newStr = new String("中文测试","UNICODE");
其实JAVA的默认编码方式就是UNICODE.

解决方案 »

  1.   

    String newStr = new String("中文测试","UNICODE");
    其实JAVA的默认编码方式就是UNICODE.
      

  2.   

    不行,执行程序报错
    "testDatabaseBean.java": Error #: 300 : constructor String(java.lang.String, java.lang.String) not found in class java.lang.String at line 42, column 23
    这是什么原因????????
      

  3.   


    没有“UNICODE”这个编码方式,标准的编码格式如下:
    US-ASCII     Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set 
    ISO-8859-1   ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1 
    UTF-8        Eight-bit Unicode Transformation Format 
    UTF-16BE     Sixteen-bit Unicode Transformation Format, big-endian byte order 
    UTF-16LE    Sixteen-bit Unicode Transformation Format, little-endian byte order 
    UTF-16       Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order  (either order accepted on input, big-endian used on output) 
      

  4.   

    String newStr = new String("中文测试".getBytes("ISO-8859-1"),"UNICODE");
      

  5.   

    // American Standard Code for Information Interchange 
        public static final String ENC_ASCII = "ASCII";
        // Windows Latin-1 
        public static final String ENC_CP1252 = "Cp1252";
        // ISO 8859-1, Latin alphabet No. 1 
        public static final String ENC_ISO8859_1 = "ISO8859_1";
        // Sixteen-bit Unicode Transformation Format, big-endian byte order
        // with byte-order 
        public static final String ENC_UTF16_BEM = "UnicodeBig";
        // Sixteen-bit Unicode Transformation Format, big-endian byte order 
        public static final String ENC_UTF16_BE = "UnicodeBigUned";
        // Sixteen-bit Unicode Transformation Format, little-endian byte order
        // with byte-order 
        public static final String ENC_UTF16_LEM = "UnicodeLittle";
        // Sixteen-bit Unicode Transformation Format, little-endian byte order 
        public static final String ENC_UTF16_LE = "UnicodeLittleUned";
        // Eight-bit Unicode Transformation Format 
        public static final String ENC_UTF8 = "UTF8";
        // Sixteen-bit Unicode Transformation Format, byte order specified by
        // a mandatory initial byte-order  
        public static final String ENC_UTF16 = "UTF-16";
      

  6.   

    说这么一大堆都没用。
    人家就需要3行输出,中文测试
    \u4e2d\u6587\u6d4b\u8bd5
    中文测试谁行?
    请教
      

  7.   

    我觉得是这样做的,
    但是由于没有办法显示出unicode的码值,所以对于现实中的应用,可能没有什么实际意义。
    欢迎批评指教
    public class Test{
      public static void main(String[] args){
        try {
            String m=new String("中文测试") ;
            System.out.println(m);
            String a = new String(m.getBytes("GBK"), "UnicodeBigUned");
            System.out.println(a);//这个a其实就是unicode码的了,
                                  //但是没有办法正确输出成\uxxxx\uyyyy形式.
                                  //就像ISO-8859-1里面的中文一样。
            System.out.println(new String(a.getBytes("UnicodeBigUned"),"GBK"));
        } catch (Exception e) {
            System.out.println(e.toString());    }
      }
    }
      

  8.   

    import sun.io.ByteToCharConverter;
    import sun.io.CharToByteConverter;public class test{
            public test(){
            }        public static void main(String[] args){
                    try{
                            ByteToCharConverter converter = ByteToCharConverter.getC
    onverter("GB2312");
                            CharToByteConverter converter1 = CharToByteConverter.get
    Converter("GB2312");
                            byte[] b = "中文测试".getBytes();
                            System.out.println(new String(b));
                            char[] c = new char[4];
                            c = converter.convertAll(b);
                            for (int i=0;i<c.length;i++){
                                    System.out.print("\\u"+Integer.toHexString(c[i])
    );
                            }
                            System.out.println();
                            byte[] b1 = new byte[8];
                            char[] c1 = {'\u4e2d','\u6587','\u6d4b','\u8bd5'};
                            b1 = converter1.convertAll(c1);
                            System.out.println(new String(b1));                }
                    catch (Exception e){
                    }
            }
    }
      

  9.   

    用了两组char数组和两组byte数组,只是为了区分而已。
      

  10.   

    其实我觉着不许要把编码转来转去的,因为默认生成的就是unicode码,需要做的就是把它的unicode码打印出来,这方面我有一些经验:)
    public class Test{
      public static void main(String[] args){
        try {
            String m=new String("中文测试");
            System.out.println(m);
            char[] c=m.toCharArray();
            for(int i=0;i<c.length;i++)
           System.out.println(new String(a.getBytes("UnicodeBigUned"),"GBK"));
        } catch (Exception e) {
            System.out.println(e.toString());    }
      }
      

  11.   

    不好意思,上面的没写好就刷新了!!
    其实我觉着不许要把编码转来转去的,因为默认生成的就是unicode码,需要做的就是把它的unicode码打印出来,这方面我有一些经验:)
    public class Test{
      public static void main(String[] args){
        try {
            String m=new String("中文测试");
            System.out.println(m);
            char[] c=m.toCharArray();
            for(int i=0;i<c.length;i++)
              System.out.println(Integer.toHexString((int)c[i]))
        } catch (Exception e) {
            System.out.println(e.toString());    }
      }
      

  12.   

    很简单的.
    import java.net.*;public class DeEncoder {
    public static void main(String[] args) throws Exception {
    String plain = "中文";
    String urlEncoded = java.net.URLEncoder.encode(plain);
    String urlDecoded = java.net.URLDecoder.decode(urlEncoded);
    System.out.println(plain + " → " + urlEncoded + " → " + urlDecoded );
    }
    }
      

  13.   


    关键就在这个Integer.toHexString方法上
    又学了一招
    不过,实在想不到居然要用到Integer的方法
    我在Character和String里面着了一个遍也没找到合用的。
      

  14.   

    joe2002,
    你的这个恐怕不是unicode吧。
      

  15.   

    我说对了,有分吗:)
    其实我当初和你差不多,在String找了个遍也没找
    呵呵
      

  16.   

    cohorse(cohorse)
    我觉得他想要的输出结果我这段程序已经实现了.我已经试验通过了.
    大家何必硬要转换呢.
      

  17.   

    java.net.URLEncoder.encode,decode
    是用get方式提交信息的时候用到的,如果不用他,有些特殊字符,如%就没法正确传递
    所以它肯定不是unicode码
      

  18.   

    joe2002(joe),你的程序我也试过啦,确实不对import java.net.*;public class DeEncoder {
    public static void main(String[] args) throws Exception {
    String plain = "你";
    String urlEncoded = java.net.URLEncoder.encode(plain);
    String urlDecoded = java.net.URLDecoder.decode(urlEncoded);
    System.out.println(plain + " → " + urlEncoded + " → " + urlDecoded );
    }
    }输出是
    你 → %C4%E3 → 你
    你不会把这个叫unicode吧,你字的unicode是\u4f60
     
      

  19.   

    我是从数据库中取得数据,用的是getbytes,取出来之后我希望把它转成UTF8在页面中显示,请问应该怎么作???
    byte[] mystr1=new byte[500];
    mystr1 = rs.getBytes("aaa");
    s2 = new String(mystr1, "UTF8");
    return s2;
    aaa是字段名称,可是显示出来是乱码,为什么???   
      

  20.   

    zha1977()
    我弄错了.谢谢前辈指教.
      

  21.   

    那UNICODE编码应该怎么显示??
      

  22.   

    我上面提到的方法里有完整的unicode转gb2312或者gb2312转unicode方案
      

  23.   

    你非要把它转成utf8缺是比较麻烦new String(mystr1, "UTF8");肯定不成
    我以前就试过,结果得到一个空串
    是在不成你只好自己写代码了,不过
    你能不能告诉我你为什麽非得转成utf8,unicode不好吗
      

  24.   

    可以用JDK1.4/bin/native2ascii.exe  your_chinese_file
      

  25.   

    public static String dumpHEX(String rStr,String rEncoding)
       {
         byte[] buf = null;
         try
         {
           if(rEncoding!=null)
             buf = rStr.getBytes(rEncoding);
           else 
             buf = rStr.getBytes();
         }catch(Exception e)
         {e.printStackTrace();}
         
         StringBuffer sb = new StringBuffer();
         for(int i=0;i<buf.length;i++)
         {
           sb.append(dumpHEXStr(buf[i])+" ");       
         }
         System.out.println(sb.toString());
         return sb.toString();
       }
       
       public static String dumpHEXStr (byte b)
       {
         return (""+"0123456789ABCDEF".charAt(0xf&b>>4)+"0123456789ABCDEF".charAt(b&0xf));
       }
      

  26.   

    高手一定要进来看,好多人期待您的回答((关于DELPHI的RES文件))
    http://www.csdn.net/Expert/topic/509/509268.shtm