How to pass hieroglyphs as an argument to the main

2019-09-16 18:08发布

问题:

I met some interesting question on which I was not able to find an answer. Does anybody know how to pass hieroglyphs as an argument to the main method from command line? Below there is some pseudo code which will help to test suggested solution:

public class Test {
    public static void main(String args[]) {
        if ("香港政府".equals(args[0])) {
            System.out.println("Match");
        }
    }
}

So question is how to call Test.class with an argument so the application prints Match to the console? args[0] can be transformed before passing to the if statement.

Thanks in advance.

回答1:

After some additional research I was able kinda figured it out. So guys who commented on question were very near to the answer. Encoding which I tried to find was 936. But it doesn't mean that you will be able to run chcp 936 if you OS locale is other than chinese. Once you will try to run it on other locale than chinese:

chcp 936

You will get following error:

Invalide code page

For making it working you have to change region. FOllowing steps will be needed:

  1. Start - COntrol panel
  2. Select "Region and Language"
  3. Select "Administrative" and click "Change system locale..."
  4. Select "Chinese (Simplified, PRC)" and reboot laptop

After restart when you will run chcp you will see following output Active code page: 936. Now you are ready to execute command line with hieroglyphs.