简体   繁体   中英

Store special characters as unicode

We have to deal with special characters frequently. Sadly no particular attention was paid to the encoding until now. As you can guess we always end up getting an encoding problem of one kind or another.

We are currently working on changing all special characters to unicode at the moment (in property files and in code (I know that this does not comply with good coding practise but we can't change this at the moment).

Now I am not quite sure how we should handel inputs from other systems with varying encodings, should we convert special characters to unicode and is there any good API or convention on how to deal with these?

If you know the original encoding you can convert it by using

String orig = "Cp1250"
BufferedReader r = new BufferedReader(new InputStreamReader(is, orig));

Where the string orig have to reflect this table . Then you can do whatever you want in code, because Java stores it internally in UTF8. If you want to persist it again in different encoding you will use a dual OutputStreamWriter with explicitly specified 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