开发者

What to consider when changing the encoding of a Java file

I need to use a few Cyrillic characters in a Java file and in order 开发者_StackOverflowfor Eclipse to allow me to do so I need to change the encoding for that file (currently to UTF-8).

Are there any problems that this could cause?


If the eclipse setting ever gets lost, or the program is built outside eclipse, the cyrillic characters could get corrupted without anyone noticing until the program performs the operations depending on them. This may or may not be an acceptable risk.

Assuming that this is about the program described in this question, a more robust alternative would be to put the cyrillic characters in an external file instead of directly into the source code, and parse that file using UTF-8 explicitly.


If it is just a few characters, you can use the \uxxxx notation:

    char[][] translate = { 
        {'\u0430', 'a'},
        {'\u0431', 'b'},
        {'\u0432', 'v'},
        {'\u0433', 'g'},
        ...
    };  

also have a look at the native2ascii tool that comes with the JDK to convert native text to unicode latin-1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜