How to solve the Chinese problem of Java
This article mainly shows you "how to solve the Java Chinese problem". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to solve the Java Chinese problem".
I'll tell you how tomcat implements JSP.
Preliminary knowledge:
1. Bytes and unicode
The Java kernel is unicode, even class files, but many media, including file / stream, are saved.
It uses byte streaming. So Java has to convert these byte streams through lines. Char is unicode and byte is byte.
The byte/char interchange function in Java is found in the middle of the sun.io package. Where the ByteToCharConverter class is the medium scheduling
Can be used to tell you that you use Convertor. Two of the commonly used static functions are
Public static ByteToCharConverter getDefault ()
Public static ByteToCharConverter getConverter (String encoding)
If you do not specify converter, the system will automatically use GBK,EN on the current Encoding,GB platform
8859_1
Let's take a simple example:
The GB code of "you" is 0xC4E3, and unicode is 0x4F60.
You use:
-encoding= "gb2312"
-- byte b [] = {(byte) u00c4, (byte) u00E3}
-- convertor=ByteToCharConverter.getConverter (encoding)
-char [] c=converter.convertAll (b)
-- for (int itemositani)