java中这个页面默认是utf-8编码的,1输出乱码可以理解,可是2就不理解了?
PHPz
PHPz 2017-04-18 10:51:36
0
2
732

s按照gbk解码,在按照gbk组合成String,为什么就不是乱码了呢? 那2这个字符串是最终是什么编码 utf-8还是gbk

PHPz
PHPz

学习是最好的投资!

reply all(2)
Peter_Zhu

1: If s.getBytes() takes no parameters, it will call the default encoding of jdk (yours may be utf-8) to decode the string into byte[], and then you use the gbk encoding method to re-encode the byte[] into string, so garbled characters will appear.

2.s.getBytes('gbk') You decode the string according to the gbk method and then re-encode it using the gbk method, so there will be no garbled characters.

洪涛

What you said above is correct. I would like to add that the default encoding of jdk is file.encoding中指定的编码,可以通过Dfile.encoding=GBKThis is how to modify the default encoding of JVM.

To add some coding and decoding knowledge, if the Chinese character "Hello" is to be transmitted in the computer, it must be converted into binary. How to convert to binary is what is mentioned heredecoding.
There are many encoding methods, such as the Unicode character set. This character set contains numbers corresponding to various symbols. For example, you is represented by 2345, which is then converted into binary in a certain way (you can find the specific process online for specific conversion methods). Unicode字符集。这个字符集里面就是各种符号对应的数字,比如用2345来表示,然后按照一定的方式转换的二进制(具体怎么转换可以网上找一下具体过程)。
接收到这一串二进制数,怎么转为汉字就是这里说的编码。编码需要按照一定的方式去解才能得到正确的字符对应关系,比如的二进制为0101010010,需要按照utf-8的方式去编码才能得到After receiving this string of binary numbers, how to convert them into Chinese characters is the

encoding🎜 mentioned here. The encoding needs to be solved in a certain way to get the correct character correspondence. For example, the binary of you is 0101010010, and it needs to be encoded according to utf-8 to get You this symbol and display it. 🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template