问题描述
在我的Swing聊天应用程序中,我有发送按钮,一个文本区域和一个文本字段。
如果我按发送按钮,我需要将文本从文本字段发送到文本区域。
请提供一些想法或代码,帮助我解决这个问题。
首先,String的内部字符表示形式是UTF-16,因此,一旦在JVM中有字符串,就不需要担心。 / p>
问题可能是通过互联网发送的字符序列和String对象之间的转换。当解析字符串时,您需要提供编码,例如。当使用 InputStreamReader
时,必须传递 Charset
参数:
必须提供编码,因为Java不能神奇地猜出字节序列的编码。
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, e.g. when using InputStreamReader
, you have to pass the Charset
parameter:
The encoding has to be provided, because Java can't magically guess the encoding of a byte sequence.
这篇关于如何在Swing应用程序中实现UTF-8格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!