【问题标题】:Eclipse Java Program to read non English characters from System.inEclipse Java 程序从 System.in 读取非英文字符
【发布时间】:2015-01-15 02:12:20
【问题描述】:

我正在运行一个简单的 java 程序,它接受 System.in 中的一行并将其拆分为空格。

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(" ");
    }

但是,每当我在梵文脚本(印地语和马拉地语的 Sctipt)中输入时,它都会得到垃圾字符。 例如如果我输入为 एक दोन तीन चार 然后在变量 devnagri 中检索为 à¤�क दोन तीन चार

我已将名为“文本文件编码”的 java 文件和项目的属性更改为 UTF-8。仍然没有帮助。 是否还有其他需要设置的 Eclipse 设置或 JVM 参数?

【问题讨论】:

    标签: java eclipse utf-8 command-line-arguments hindi


    【解决方案1】:

    当我在命令行上给出 -Dfile.encoding=UTF-8 时,它对我有用。我不知道 Eclipse 中的设置是否会产生这样的 JVM 参数,或者您是否需要提供 JVM 参数作为运行配置的一部分。

    【讨论】:

      【解决方案2】:

      试试,

      1. Windows > Preferences > General > Content Types,

        UTF-8 设置为所有内容类型的默认编码。

      2. Windows > Preferences > General > Workspace,

        "Text file encoding" 设置为"Other : UTF-8"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-25
        相关资源
        最近更新 更多