简体   繁体   中英

how to implement UTF-8 format in Swing application?

In my Swing chat application i am having the send button, one text area, and a text field.

If I press Send button, I need to send the text from text field to text area. It is working fine in English but not in local language.

Please give some idea or some code that will help me to solve this.

First of all, the internal character representation of String is UTF-16, so you don't need to worry once you have the string in your JVM.

The problem is probably the conversion between a sequence of characters that gets sent over the internet and a String object. When parsing a string you need to provide the encoding, eg when using InputStreamReader , you have to pass the Charset parameter:

InputStreamReader(InputStream in, Charset cs)
Create an InputStreamReader that uses the given charset.

The encoding has to be provided, because Java can't magically guess the encoding of a byte sequence.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM