简体   繁体   中英

Long string convert to UTF-8 throws exception

I am using GWT, and have a very long string from RichTextArea and I want to convert it to UTF-8 before sending to the server:

String content = new String(rta.getText().getBytes(), "UTF-8");

However this one throws an exception saying:

 [Range Error]: Maximum call stack size exceeded

Is this a bug?

RichTextArea.getText returns a String . The operation you are doing to "convert to utf-8" is not correct. There is no need to convert a java String to any character encoding. The code you have is getting the bytes in the default character encoding of the platform and then interpreting them as utf-8. At best this is a lot of work to get back to the exact same String . At worst (say platform encoding of utf-16le) you mangle your String data completely.

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