Setting the default Java character encoding

后端 未结 17 2064
终归单人心
终归单人心 2020-11-21 06:09

How do I properly set the default character encoding used by the JVM (1.5.x) programmatically?

I have read that -Dfile.encoding=whatever used to be the

17条回答
  •  别那么骄傲
    2020-11-21 07:02

    Solve this problem in my project. Hope it helps someone.

    I use LIBGDX java framework and also had this issue in my android studio project. In Mac OS encoding is correct, but in Windows 10 special characters and symbols and also russian characters show as questions like: ????? and other incorrect symbols.

    1. Change in android studio project settings: File->Settings...->Editor-> File Encodings to UTF-8 in all three fields (Global Encoding, Project Encoding and Default below).

    2. In any java file set:

      System.setProperty("file.encoding","UTF-8");

    3. And for test print debug log:

      System.out.println("My project encoding is : "+ Charset.defaultCharset());

提交回复
热议问题