I recently encountered a problem of converting byte characters into Chinese characters when I was developing the mobile phone's j2_c program. Later, I got some advice from various experts and finally solved the problem. I would like to thank all experts for their great thanks, below are our chat records, so I am too lazy to sort them out.
Guangzhou-corner stone (421340465) 09:58:24
How can I convert the Chinese byte group of asc2 into Chinese characters?
Guangzhou-corner stone (421340465) 09:59:30
New String (cmdbyte, 0, datalen) is garbled,
The new string (cmdbyte, "gb2312") is not supported by the agent ");
Xiao Yiqing (379880437) 10:00:19
You can convert it to UTF-8.
Xiao Yiqing (379880437) 09:59:21
You can see some of the JDK commands ..
Guangzhou-corner stone (421340465) 10:00:47
New String (cmdbyte, "UTF-8 ")?
Xiao Yiqing (379880437) 10:01:13
New String (Str. getbytes ("iso-8859-1"), "UTF-8 ");
Xiao Yiqing (379880437) 10:01:21
This will certainly be a transfer.
Guangzhou-corner stone (421340465) 10:02:46
What does STR mean?
Xiao Yiqing (379880437) 10:02:59
The string you want to convert.
Xiao Yiqing (379880437) 10:04:31
OK?
Guangzhou-corner stone (421340465) 10:04:41
Chinese characters have been converted to byte arrays. Now I want to restore Chinese characters that are already byte arrays to Chinese characters.
Guangzhou-corner stone (421340465) 10:04:45
Try
Xiao Yiqing (379880437) 10:04:52
Byte array ..
Guangzhou-corner stone (421340465) 10:05:10
Yes, Chinese characters are sent from the serial port to my program
Xiao Yiqing (379880437) 10:05:14
Well.
Xiao Yiqing (379880437) 10:05:23
?
Xiao Yiqing (379880437) 10:05:26
Don't understand...
Xiao Yiqing (379880437) 10:05:28
What do you mean?
Guangzhou-corner stone (421340465) 10:05:34
After receiving it in a program, I convert it into Chinese.
Xiao Yiqing (379880437) 10:05:51
New String (byte [], "UTF-8 ");
Guangzhou-corner stone (421340465) 10:06:01
Oh, trying
Xiao Yiqing (379880437) 10:06:15
The effect should be the same ..
Xiao Yiqing (379880437) 10:06:27
Haha
@... (749560730) 10:09:46
Looking for a job... Cheap ....
Xiao Yiqing (379880437) 10:09:56
Evil ..
Xiao Yiqing (379880437) 10:10:11
..
Guangzhou-corner stone (421340465) 10:10:11
Xiao Yiqing
No. It is not supported either.
Xiao Yiqing (379880437) 10:10:23
How is it possible?
Guangzhou-corner stone (421340465) 10:10:25
Required STR = new string (cmdbyte, "UTF-8 ");
Xiao Yiqing (379880437) 10:10:39
I used to do this all the time ..
Guangzhou-corner stone (421340465) 10:10:41
The Chinese character is sent from the serial port to my program. After receiving the Chinese character, I convert it into Chinese.
Guangzhou-corner stone (421340465) 10:11:08
That's it.
The Code sent from the serial port should be asc2.
Xiao Yiqing (379880437) 10:11:19
I know what cmdbyte is.
Xiao Yiqing (379880437) 10:11:22
How to convert.
Guangzhou-corner stone (421340465) 10:11:29
Required STR = new string (cmdbyte, "UTF-8 ");
Guangzhou-corner stone (421340465) 10:11:43
Cmdbyte is all the data received from the serial port.
Guangzhou-corner stone (421340465) 10:11:50
Byte array
Xiao Yiqing (379880437) 10:12:09
Print out what it is ..
Xiao Yiqing (379880437) 10:12:25
I'm dizzy.
Guangzhou-corner stone (421340465) 10:12:50
Is it not supported by J2EE?
Xiao Yiqing (379880437) 10:13:06
This is generally not the case.
Guangzhou-corner stone (421340465) 10:13:06
I am running it on a real machine.
Guangzhou-corner stone (421340465) 10:13:20
So there is no print
Xiao Yiqing (379880437) 10:13:25
Remote sharing?
Guangzhou-corner stone (421340465) 10:14:08
How to share it? I won't.
Prodigal Son-J2EE (379880437) 10:14:36
I'm dizzy ..
Prodigal Son-J2EE (379880437) 10:14:40
Then I'm speechless.
Guangzhou-corner stone (421340465) 10:15:20
My debugging is not online debugging
Prodigal Son-J2EE (379880437) 10:15:44
I know !!! Khan.
Prodigal Son-J2EE (379880437) 10:16:02
You just try it.
Prodigal Son-J2EE (379880437) 10:16:23
New String (Str. getbytes ("iso-8859-1"), "UTF-8 ");
Guangzhou-corner stone (421340465) 10:16:22
I don't know much about new things, so I'm not ashamed to ask. Well, let's take a look. Let's see what's not done there. I can't ask you any more.
Prodigal Son-J2EE (379880437) 10:16:27
Then output
Prodigal Son-J2EE (379880437) 10:16:38
My technology is also bad.
Guangzhou-corner stone (421340465) 10:16:40
New String (Str. getbytes ("iso-8859-1"), "UTF-8 ");
This is acceptable,
Prodigal Son-J2EE (379880437) 10:16:50
So?
Guangzhou-corner stone (421340465) 10:17:00
The Chinese character is sent from the serial port to my program. After receiving the Chinese character, I convert it into Chinese.
Prodigal Son-J2EE (379880437) 10:17:17
Str. getbytes ("iso-8859-1") to the byte array will not work?
Guangzhou-corner stone (421340465) 10:17:55
No. I tried it just now. Let's take a look and check again.
Guangzhou-corner stone (421340465) 10:18:05
I think it's strange.
Prodigal Son-J2EE (379880437) 10:18:17
Generally, this parameter does not exist ..
Caotang knight → Java (67417493) 10:30:19
Bytearrayoutputstream bos1 = new bytearrayoutputstream ();
Dataoutputstream dos1 = new dataoutputstream (
Bos1 );
Dos1.writeutf (S1 );
Byte B2 [] = bos1.tobytearray ();
Rs. setrecord (2, B2, 0, b2.length );
Caotang knight → Java (67417493) 10:30:39
Are you reading it from the stream?
Caotang knight → Java (67417493) 10:30:43
The one above
Prodigal Son-J2EE (379880437) 10:30:48
Haha
Caotang knight → Java (67417493) 10:30:48
Save first
Guangzhou-corner stone (421340465) 10:30:48
Yes
Caotang knight → Java (67417493) 10:31:00
Have you seen it?
Caotang knight → Java (67417493) 10:31:19
You can read it in the stream. If it is saved, you can use it to save it.
Caotang knight → Java (67417493) 10:31:40
If it is not saved, use writeutf
Prodigal Son-J2EE (379880437) 10:31:42
Ask a question about the j2's process ..
Guangzhou-corner stone (421340465) 10:31:44
But I want to convert it to Chinese.
Caotang knight → Java (67417493) 10:32:00
Code I want to convert
Guangzhou-corner stone (421340465) 10:32:22
Okay, thank you,
Caotang knight → Java (67417493) 10:32:29
Byte utfbytes [] = Rs. getrecord (9 );
Datainputstream Dis = new datainputstream (
New bytearrayinputstream (utfbytes ));
String content = dis. readutf ();
Caotang knight → Java (67417493) 10:32:42
This is read from RMS.
Caotang knight → Java (67417493) 10:32:46
Saved just now
Caotang knight → Java (67417493) 10:33:10
On the mobile phone, if it is saved, you have to write it once and read it once.
Guangzhou-corner stone (421340465) 10:33:17
Oh
Guangzhou-corner stone (421340465) 10:33:23
Why do we need to save the file before converting it?
Caotang knight → Java (67417493) 10:33:30
If you do not save the data, directly read the data and use the read data.
Caotang knight → Java (67417493) 10:33:44
Only UTF-8 is supported on the phone
Caotang knight → Java (67417493) 10:33:52
Conversion not supported
Caotang knight → Java (67417493) 10:34:13
All the data you pass is binary, and all the data you read is garbled.
Guangzhou-corner stone (421340465) 10:34:24
Oh, no wonder
Caotang knight → Java (67417493) 10:34:32
I used to study it for half a day.
Caotang knight → Java (67417493) 10:35:07
Why can't he get YD from his broken table!
Caotang knight → Java (67417493) 10:35:16
If yes, do it.
Guangzhou-corner stone (421340465) 10:35:25
Ma Ti, Nb is dead, OK
Guangzhou-corner stone (421340465) 10:35:45
Let me try it. Thank you.
Caotang knight → Java (67417493) 10:35:51
You're welcome.
Caotang knight → Java (67417493) 10:36:06
I am also knowledgeable