Java Chinese garbled solution

xiaoxiao2021-04-10  548

In Java-based programming, there is often a problem with the Chinese characters and display, such as a lot of garbled or question marks. This is because the default encoding mode in Java is Unicode, and the documents and DBs commonly used by Chinese people are based on GB2312 or BIG5 and other codes, so this problem will occur. I used to worry about this problem, and later I checked some information, I finally solved it. I know that there must be many friends will encounter this problem, so I have summed up, come out to let everyone share it. 1. Output Chinese in the web page. Java is encoded in network transmission is "ISO-8859-1", so it is necessary to transform when output, such as string str = "Chinese"; str = new string (str.getbytes ("GB2312"), "8859_1) "); But if the code is used when the program is compiled, the code is" GB2312 ", and this program is run on the Chinese platform, and this problem will not be noted. 2. Read Chinese from the parameters This is just as: str = new string (str.getbytes ("8859_1"), "GB2312"), "GB2312"); 3, a simpler method in operating the Chinese problem in DB Yes: In "Control Field", set the "region" to "English (US)". If there is a garbled, you can set the following: Take Chinese: str = new string (Str.getBytes)); Enter Chinese to DB: Str = New String (Str.getbytes ("ISO-8859 -1 ")); 4 in JSP Solution: In" Control Field ", set the" region "to" English (US) ". Join in the JSP page: If it still does not display properly, To perform the following conversion:, if: name = new string (Name.getbytes ("ISO-8859-1"), "GBK"); there will be no Chinese problem.

-------------------------------------------------- -------------------------------------------------- --------------------

Below is a small program I have to do with IO, this is one of them

FileinputStream Fis = New FileInputStream ("file.txt"); stringbuffer s = new stringbuffer (); int C; while ((c = fis.read ())! = - 1) // {s = S.Append (( CHAR) C);} Byte B [] = S.toTString (). getBytes ("ISO8859-1"); for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-133489.html

New Post(0)