0

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. e.g. 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 ?

Kaushik Lele
  • 6,439
  • 13
  • 50
  • 76

2 Answers2

0

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.

David Conrad
  • 15,432
  • 2
  • 42
  • 54
0

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".

Rakesh KR
  • 6,357
  • 5
  • 40
  • 55