无法打印印地文字符

时间:2012-09-24 15:24:29

标签: java

Output_Screen

public class demo {

    public static void main(String[] args) {
        for(int k = 2029; k<=2360 ; k++)
        {
            System.out.print(k+  " "+(char)k+" ");
        }
    }
}

输出:

2029 ? 2030 ? 2031 ? 2032 ? 2033 ? 2034 ? 2035 ? 2036 ? 2037 ? 2038 ? 2039 ? 2040 ? 2041 ? 2042 ? 2043 ? 2044 ? 2045 ? 2046 ? 2047 ? 2048 ? 2049 ? 2050 ? 2051 ? 2052 ? 2053 ? 2054 ? 2055 ? 2056 ? 2057 ? 2058 ? 2059 ? 2060 ? 2061 ? 2062 ? 2063 ? 2064 ? 2065 ? 2066 ? 2067 ? 2068 ? 2069 ? 2070 ? and so on..

此输出显示在cmd上... 为什么它不显示印地文字符....

3 个答案:

答案 0 :(得分:5)

在Eclipse中:

您需要将Eclipse控制台编码更改为UTF-8。为此,请转到运行配置对话框,然后选择常用标签。在编码下,选择UTF-8。现在运行你的程序。您应该在Eclipse控制台中看到打印的印地文字符。

答案 1 :(得分:2)

在Intellij下运行程序时遇到了同样的问题。我通过更改

中的调试命令行来修复

-Dfile.encoding = windows-1251 to -Dfile.encoding = utf-8

Intellij将默认文件编码设置为不适用于印地语的值。我的日食生锈了,但看看你是否可以将调试器的vm选项更改为-Dfile.encoding = utf-8

答案 2 :(得分:2)

如果您创建一个文件说.properties文件以进行国际化,那么Eclipse具有内置的unicode编辑器。 如果在RUN Configuration Common选项卡下启用。在Console Encoding =&gt; Other下选择UTF-8。 然后控制台将以您选择的语言阅读它。您仍然需要为文件提供unicode字符,或者将字符转换为UNICODE。

现在,如果你的语言字符在hindiविमलकृष्णा(在某些编辑器中需要这些字符),那么如果我只是粘贴在eclipse .properties文件中,它将自动转换为\ u0935 \ u093F \ u092E \ u0932 \ u0915 \ u0943 \ u0937 \ u094D \ u0923 \ u093E。

上面的字符串现在将在控制台中解释为विमलकृष्णा。

实施例: 步骤1 在Spring中,你需要在一个名为“locale”的文件夹下的classpath(比如在src / main / resources中)一个名为

的文件 带有内容的

messages_hi_IN.properties (对于印地语)

user.name=\u0935\u093F\u092E\u0932 \u0915\u0943\u0937\u094D\u0923\u093E, age : {0}, URL : {1}
内容

messages_en_US.properties (英文)

user.name=vimal krishna, age : {0}, URL : {1}

第2步:

你主要申请:

package com.vimal.common;

import java.text.SimpleDateFormat;
import java.util.Locale;

 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;

 public class App {
      public static void main(String[] args) {

       ApplicationContext context 
        = new ClassPathXmlApplicationContext("com/vimal/common/beans.xml");

       String name = context.getMessage("user.name", new Object[] { 45,"http://www.vkrishna.com" }, Locale.US);

    System.out.println("User name (English) : " + name);

    String nameHindi = context.getMessage("user.name", new Object[] {45, "http://www.vkrishna.com" }, new Locale("hi", "IN"));

    System.out.println("User name (Hindi) : " + nameHindi);

  }
}

第3步:配置文件

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans      
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>locale\messages</value>
    </property>
</bean>

此处 locale 是src / main / resources中的文件夹,该文件夹位于类路径上(如果maclipse项目由eclipse创建),messages_hi_IN.properties文件位于该文件夹中。 locale \ messages引用此消息 _hi_IN.properties文件,添加hi_IN是hindi的区域设置检测的关键。 现在在主应用程序中,您可以看到创建了一个新的Locale(“hi”,“IN”),因为它没有在eclipse中定义,如locale.US和其他。

结果将是:

Dez 31, 2014 12:19:12 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFORMATION: Pre-instantiating singletons in   org.springframework.beans.factory.support.DefaultListableBeanFactory@5594a1b5: defining beans [messageSource]; root of factory hierarchy
Customer name (English) : vimal krishna, age : 45, URL : http://www.vkrishna.com
Customer name (Hindi) : विमल कृष्णा, age : ४५, URL : http://www.vkrishna.com

我重写了link...

相关问题