简体   繁体   中英

Apache Commons ToStringBuilder String encoding

I'm using Apache Commons' ToStringBuilder to generate entities toString's block content. But for some entities, there are String fields encoded with "ISO-8859-15", so I'm wondering if the produced toString will use platform's default (UTF-8 on my vm) with values outputed incorrectly.

Thanks for your help

Java strings are always using Unicode for characters.

Encoding only becomes an issue when reading/writing strings from/to files. Or when converting strings into byte arrays for example.

In that sense: you do not have to worry about the string builder. You have to worry about "where are is the data initially coming from" respectively "going to".

Just for completeness: yes, the Java String class has a constructor where you can pass in the desired encoding - but that constructor also takes an array of bytes as first argument. And as said: in such cases you have to worry about encoding.

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