How to use UTF-8 / Unicode in J-Creator?

232 Views Asked by At

I'm trying to do a project for a programming class, and I need to figure out how to be able to get unicode working in J-Creator, if possible. I haven't been able to find anything so far. When I try to print a word in a non-latin alphabet, such as "цитата", it prints "??????". How to I get UTF-8 in J-Creator?

1

There are 1 best solutions below

0
skomisa On

I don't use JCreator, and therefore couldn't verify this answer, but it may still be helpful since there are three general points to consider when rendering UTF-8 text from a Java application to a terminal window:

  1. Assuming that you are using the PrintStream method println() to display your text in JCreator's terminal window, you probably need to instantiate that PrintStream to explicitly use the character encoding UTF-8:

     try{
         PrintStream outStream = new PrintStream(System.out, true, "UTF-8");
         outStream.println("цитата");
     } catch(UnsupportedEncodingException e){
         // Error handling
     } 
    

If you don't do that, and simply call System.out.println("цитата"); instead, then you will be using the default encoding at runtime. That is determined by the JVM during startup, and is unlikely to be UTF-8.

  1. You may need to set the code page in the terminal window to UTF-8. You don't mention your operating system, but from a terminal on Windows (e.g. PowerShell, Command Prompt, etc.) you would call chcp 65001. That may or may not be applicable for your environment, and I have no idea whether JCreator even allows you set the code page when running your application.

  2. You obviously must use a font which supports the text being rendered within the terminal window, which is Russian in your case. I don't know how JCreator determines the font to use and whether it allows you to explicitly set that font, but it can be set for a Command Prompt window on Windows.

It's possible that despite your best efforts the JCreator terminal simply won't support what you want to do. In that case your workaround will be to use a terminal window supported by your operating system and run your application there, assuming that you are able to set the code page and the font.