如何从文件中读取Unicode字符 [英] how to read Unicode character from files

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

问题描述

嗨朋友
如何阅读Unicode charcater
我尝试但显示了字符(?????)
如果有样品请给我
谢谢alt

hi friends
how to read Unicode charcater
i try but character is shown (?????)
if you have sample give me
thanks alot

推荐答案

文件使用特定的字符集编写.

而且"unicode"还不足以识别正在使用哪个字符集.常见的(但不是唯一的可能性)包括8位和16位变体,其中16位变体包括字节顺序.

确定字符集后,然后使用适当的编码打开文件.

打开具有特定编码的文件的一个示例如下

InputStreamReader(stream,"UTF-8")


还要记住,仅仅因为您正确阅读了它并不意味着您可以正确显示它.这是两个不同的部分.
Files are written with a specific character set.

And "unicode" is not enough to identify which character set is is use. Common (but not the only possibility) include 8 bit and 16 bit variations, where the 16 bit variation includes byte order.

AFTER you determine the character set then you open the file using the appropriate encoding.

ONE example of opening a file like that with a specific encoding is as follows

InputStreamReader(stream, "UTF-8")


Further keep in mind that just because you read it correctly it does not mean that you can display it correctly. Those are two distinct parts.


快速而简单:

quick and simple:

Reader oReader = new InputStreamReader(new FileInputStream("file"), "UTF-8"));
String strUTF8Text = null;

while(true){ // infinit loop
  String strLine = oReader.readLine();
  if(null== strLine) break; // exit point
  strUTF8Text += strLine;
}



另请阅读此处以获取有关字节编码和字符串" [ ^ ].



Please also read here for much more information about "Byte Encodings and Strings"[^] in the Java Tutorials.


这篇关于如何从文件中读取Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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