PDA

View Full Version : Unicoded Problem!!


iiley
05-03-2002, 06:56 PM
I know the text and String use Unicode in FlashMX,and,I know the String and char in java is Unicoded too!
but,i have a XMLSocket Server App builded by java,and the Client builded by FlashMX,the communicate correctly in English charaters,but wrong in Chinese charaters(16bit one character),in java window the charaters become some different wrong character.sand,we know that the Unicode support different Language charaters,but,where is my mistake?
the reader code in java like this:

in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
......
char charBuffer[] = new char[1];
while(in.read(charBuffer,0,1) != -1 && this.ip==null) {
StringBuffer stringBuffer = new StringBuffer(256);
while(charBuffer[0] != '\0'){
stringBuffer.append(charBuffer[0]);
in.read(charBuffer, 0 ,1);
}
String tempStr=stringBuffer.toString();
System.out.println("the message is:"+tempStr);
}
.....

and the actionscripts like this:

......
MyMXLSocket.send(new XML(<TESTMSG>characters in Chinese</TESTMSG>));

but the java output is:
the message is:<TESTMSG>some different strange characters</TESTMSG>

oh~my god,i was puzzled!
hope you can understand my meaning with my poor English:(
thanx in advance!

iiley
05-06-2002, 08:51 AM
yeah~~~~I succeed,i replace that codes to this:

in = new BufferedReader(
new InputStreamReader(
socket.getInputStream(),"UTF-8"));

some help for others~:D

Jesse
05-06-2002, 12:21 PM
Glad you solved your problem. Thanks for posting a resolution.

iiley
05-06-2002, 05:36 PM
:)
but,the new strang thing is that Chinese is a type of Character used 16bits,but the UTF-8 encoding use 8bits one Character??
is it right?I can't understand how a 8bits encoding can work with 16bits Characters?

Jesse
05-07-2002, 02:27 PM
Sorry I have no experience with such things.

iiley
05-08-2002, 10:06 AM
Doesnt matter~;)
Thank you in the same,I think some must knows and he/she will give us a help in future!
:cool: