charset cp852 and ISO 8859-2

2019-08-06 12:55发布

Is it possible that while loading characters from .dbf file with charset cp852 to

ArrayList<Map<String, Object>>();

and save that to xml file with encoding ISO 8859-2 can occur data loss?

In internet explorer and java collections all charset seems to be ok, but when I add data from xml to database I lose my letters like ą, Ą , ś, Ś

1条回答
别忘想泡老子
2楼-- · 2019-08-06 13:31

yes, it is pretty much possible as displayed on this code (though it will be fine if you only want to export simple letter).

public class Sample {
    public static void main(String[] args) throws Exception {
        // try to print Upper case A with ogonek
        System.out.println(new String(new byte[] {(byte) 164}, Charset.forName("IBM852"))); // <--- will print the correct character
        System.out.println(new String(new byte[] {(byte) 164}, Charset.forName("ISO-8859-2"))); // <--- will print something else
    }
}

the result in my place will look like this

Ą
¤

for further reference, you could check these two links

http://www.ascii-codes.com/cp852.html
http://www.calculla.com/en/iso8859_2_table?action=showAll

查看更多
登录 后发表回答