简体   繁体   中英

Eclipse Java Program to read non English characters from System.in

I am running a simple java program which accepts a line from System.in and splits it for spaces.

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String word="",type="";
    while(!word.equalsIgnoreCase("stop")){
      System.out.println("Enter word");
      String devnagri = sc.nextLine();
      String [] devnagriSpilt = devnagri.split(" ");
    }

But whenever I give input in Devanagari script (Sctipt for Hindi and Marathi languages) it gets garbage characters. eg If I give input as एक दोन तीन चार Then is retrieved in variable devnagri as ठक दोन तीन चार

I have changed the property of java file and project named "Text file encoding" as UTF-8. Still it does not help. Is there any other Eclipse setting or JVM argument that needs to be setup ?

It works for me when I give -Dfile.encoding=UTF-8 on the command line. I don't know if that setting in Eclipse yields such a JVM argument or if you need to supply the JVM argument as part of the run config.

Try,

  1. Windows > Preferences > General > Content Types ,

    set UTF-8 as the default encoding for all content types.

  2. Windows > Preferences > General > Workspace ,

    set "Text file encoding" to "Other : UTF-8" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM