从.properties文件取值时,需要进行字节转换!才能显示中文

解决方案 »

  1.   

    要如何做,代码写在哪,xmvigour(微电) 快帮忙
      

  2.   

    ResourceBundle rb = ResourceBundle.getBundle("lwz");
    String author = GB2Unicode(rb.getString("lwz.author"));
    public static String GB2Unicode(String s) {
        if(s == null)
        {
    return s;
        }
        char[] orig = s.toCharArray();
        byte[] dest = new byte[orig.length];
        for (int i=0;i<orig.length;i++)
           dest[i] = (byte)(orig[i]&0xFF);
        try
        {
           ByteToCharConverter toChar = ByteToCharConverter.getConverter("GBK");
           return new String(toChar.convertAll(dest));
        }
        catch (Exception e)
        {
         System.out.println(e);
         return s;
        }
    }