在Java中打印Unicode字符 [英] Print unicode character in java

查看:804
本文介绍了在Java中打印Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中显示unicode字符显示?"标志.例如,我尝试打印अ".其unicode编号为U + 0905,并且html表示形式为अ". 下面的代码打印?"而不是unicode字符.

Displaying unicode character in java shows "?" sign. For example, i tried to print "अ". Its unicode Number is U+0905 and html representation is "अ". The below codes prints "?" instead of unicode character.

char aa = '\u0905';
String myString = aa + " result" ;
System.out.println(myString); // displays "? result"

是否有一种方法可以直接从unicode本身显示unicode字符而无需使用unicode数字?即अ"已保存在文件中,现在在jsp中显示该文件.

Is there a way to display unicode character directly from unicode itself without using unicode numbers? i.e "अ" is saved in file now display the file in jsp.

推荐答案

尝试使用utf8字符集-

try to use utf8 character set -

        Charset utf8 = Charset.forName("UTF-8");
        Charset def = Charset.defaultCharset();

        String charToPrint = "u0905";

        byte[] bytes = charToPrint.getBytes("UTF-8");
        String message = new String(bytes , def.name());

        PrintStream printStream = new PrintStream(System.out, true, utf8.name());
        printStream.println(message); // should print your character

这篇关于在Java中打印Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆