我做一个软件汉化的时候翻译一个资源文件,
它的汉字是用\u5fc5\u987b\u8f93\u5165表示的时候显示出来没问题,但我如果将其改为汉字则在显示的时候会出现乱码,该如何解决啊,
我的运行环境是WebLogic我想将汉字转换为\u5fc5\u987b\u8f93\u5165这中串,这个方法可行吗,还有没更好的方法,如果要将汉字转换为\u5fc5\u987b\u8f93\u5165格式,程序该怎么写啊
高手请赐教,问题如解决分可以再加

解决方案 »

  1.   

    如果你设置了JAVA环境变量
    直接可以运行native2ascii
    在javahome\bin下有这个的native2ascii ApplicationResources.properties.GBK ApplicationResources_zh_CN.properties
    上面的命令是把ApplicationResources.properties.GBK文件 转换为ApplicationResources_zh_CN.properties文件 GBK里的就是你说的中文内容,后面的文件是你需要的文件
      

  2.   

    很简单阿,把java.util.Properties里的saveConvert方法copy出来就可以了。  public static void main(String[] args) {
        System.out.println(toUnicode("汉字aaa",true));
      }  /*
       * Converts unicodes to encoded \uxxxx and escapes
       * special characters with a preceding slash
       */
      public static String toUnicode(String theString, boolean escapeSpace) {
        int len = theString.length();
        int bufLen = len * 2;
        if (bufLen < 0) {
          bufLen = Integer.MAX_VALUE;
        }
        StringBuffer outBuffer = new StringBuffer(bufLen);    for (int x = 0; x < len; x++) {
          char aChar = theString.charAt(x);
          // Handle common case first, selecting largest block that
          // avoids the specials below
          if ( (aChar > 61) && (aChar < 127)) {
            if (aChar == '\\') {
              outBuffer.append('\\');
              outBuffer.append('\\');
              continue;
            }
            outBuffer.append(aChar);
            continue;
          }
          switch (aChar) {
            case ' ':
              if (x == 0 || escapeSpace) {
                outBuffer.append('\\');
              }
              outBuffer.append(' ');
              break;
            case '\t':
              outBuffer.append('\\');
              outBuffer.append('t');
              break;
            case '\n':
              outBuffer.append('\\');
              outBuffer.append('n');
              break;
            case '\r':
              outBuffer.append('\\');
              outBuffer.append('r');
              break;
            case '\f':
              outBuffer.append('\\');
              outBuffer.append('f');
              break;
            case '=': // Fall through
            case ':': // Fall through
            case '#': // Fall through
            case '!':
              outBuffer.append('\\');
              outBuffer.append(aChar);
              break;
            default:
              if ( (aChar < 0x0020) || (aChar > 0x007e)) {
                outBuffer.append('\\');
                outBuffer.append('u');
                outBuffer.append(toHex( (aChar >> 12) & 0xF));
                outBuffer.append(toHex( (aChar >> 8) & 0xF));
                outBuffer.append(toHex( (aChar >> 4) & 0xF));
                outBuffer.append(toHex(aChar & 0xF));
              }
              else {
                outBuffer.append(aChar);
              }
          }
        }
        return outBuffer.toString();
      }  private static char toHex(int nibble) {
        return hexDigit[ (nibble & 0xF)];
      }  private static final char[] hexDigit = {
          '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
          'F'
      };
      

  3.   

    String s="中";
    int chr=(char)s.charAt(0);
    String result= "\\u" + Integer.toHexString(chr);
      

  4.   

    to:miaoliujun(傲龙)
    我按你的方法

    errors.required={0} 必须输入.
    转换后结果为:
     e r r o r s . r e q u i r e d = { 0 }   \u81fa{\u69d7\u5ef5Q. 
    我要得到
    errors.required={0} \u81fa{\u69d7\u5ef5Q.该如何处理啊
    因为我只要对汉字部分进行转换
    请赐教,拜托了!!!
      

  5.   

    to: pigo(不成功,便成练习) 
    你的方法是可以但是我有一个文件需要转换
    若从文件中读取、转换、再存到文件中则它会把非汉字的也转换为\u5fc5\u987b\u8f93\u5165类型了
    main代码:
    public static void main(String[] args) {
    File f = new File(args[0]);
    File fw = new File(args[1]);

    InputStreamReader read;
    OutputStreamWriter write;
    try {
    fw.createNewFile();
    read = new InputStreamReader (new FileInputStream(f),"UTF-8");
    write = new OutputStreamWriter (new FileOutputStream(fw),"UTF-8");
    BufferedReader reader=new BufferedReader(read);
    BufferedWriter writer=new BufferedWriter(write); String line;
    while ((line = reader.readLine()) != null) {
    String s=toUnicode(line,true);
    writer.write(s);
    }

    read.close();
    write.close(); } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
      }应该是读取文件的问题,应该怎么改啊?