Display special characters using System.out.println

自古美人都是妖i 提交于 2019-11-26 22:45:41

Yeah, its the XXI. century and we're still struggling with things like character encoding...

My first guess is that either:

  1. your source file encoding might be wrong (do you use build tools like Maven? It might be needed to set the source-encoding there too),
  2. your console encoding might be wrong (are you under Windows? The default command line console is not UTF by default, its local-dependant, but with a small play in the registry you can set its encoding)
  3. your DB encoding might be incorrect (what is the Table encoding, can you check that?)

If you are using Eclipse, then

  1. right click on you project.
  2. Go to Properties
  3. Select UTF-8 in "Text File Encoding "

See if this works.

    PrintStream out = new PrintStream(System.out, true, "UTF-8");
    out.println(test);

For storing in DB, use following to explicitly encode the string in UTF-8

String newString = new String(test.getBytes(), "UTF8");

may be you need to decode your character string to ISO-8859 first and then encode it to UTF-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!