Java用\u读取unicode [英] Java read unicode with \u

查看:46
本文介绍了Java用\u读取unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 java 程序正在从文本文件中读取 unicode.例如\uffff..从java GUI查看是没有问题的,但是当我尝试打印出来时,所有的文字都被覆盖了,是因为\u,还是其他避免文字被覆盖的方法?

My java program is reading unicode from text file. e.g. \uffff.. View from the java GUI is no problem, but when i try to print out, all wording are overwritten, is it because of \u, or any other way to avoid the words overwritten?

抱歉我的英语不好..谢谢.

sorry about my broken english.. thanks.

推荐答案

符号 \uXXXX 主要只出现在 .java.properties> 文件.在那里它被读取为 Unicode 代码点.Unicode 文本(=使用所有类型的特殊字符)通常使用 UTF-8 格式(尽管有时也会使用 UTF16LE 和 UTF16BE).

The notation \uXXXX primarily only occures in .java and .properties files. There it is read as a Unicode code point. Unicode text (=using all kind of special characters) often uses the UTF-8 format (though also sometimes UTF16LE and UTF16BE are used).

这段文字读作:

BufferedReader in = new BufferedReader(
        new InputStreamReader(new FileInputStream(file), "UTF-8"));

并且(为了更好的顺序)写成

And (for good order) written as

new OutputStreamWriter(new FileOutputStream(file), "UTF-8")
new PrintWriter(file, "UTF-8")

尤其是不是 FileReader 和 FileWriter 旧实用程序类使用平台编码.

Especially not with FileReader and FileWriter which old utility classes use the platform encoding.

如果文本会包含 \u20AC,那将是不规则的,并且会按字面打印(反斜杠,u,20AC),

IF the text would countain \u20AC, that would be irregular, and would be printed literally (backslash, u, 20AC),

现在,如果您的意思是 Unicode 字符在正常 ASCII 范围之外存在问题,例如欧元符号 ,那么这可能是字体问题或需要的转换,例如Windows 拉丁语 1:"Windows-1252".

Now if you mean there are problems with Unicode characters out of the normal ASCII range, like for the euro symbol , then it might be a matter of font, or a needed conversion, say to Windows Latin 1: "Windows-1252".

这篇关于Java用\u读取unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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