I’m trying to build a Chinese flashcards program in Java to help myself learn Chinese. I’m using intelliJ IDEA 10. The basic process is that my program will read a file saved on the local machine to generate the flashcards. The file is written using the File class in java. When opened in notepad, it displays all characters properly.
When I run it in the IDE I am able to display Chinese characters as well as pinyin characters(basically vowels with accent marks over them). However, when I built a jar file and launch the program from there, it can no longer display special characters and ends up showing a bunch of weird symbols.
Any ideas on why this is and how to fix it?
IntelliJ doesn’t use the platform default encoding, it autodetects it based on the encoding of the source files. When running the code outside IntelliJ, you need to ensure that you explicitly specify the proper encoding when reading/writing the file. You can do that by specifying it as 2nd constructor argument of
InputStreamReaderandOutputStreamWriterrespectively.Further you also need to ensure that the viewer supports the fonts as well. Windows Command Console for example, doesn’t support Chinese. You’d need to create a Swing application to present the results instead.