如何解析从java中的文件中读取的unicode [英] how to parse unicode that is read from a file in java

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

问题描述

我写了一个包含以下内容的文本文件: \ u0032 \ u0142o \ u017Cy \ u0142

I have written a text file with the following contents: \u0032\u0142o\u017Cy\u0142

然后我使用FileReader和BufferedReader来读取文件。

Then I have used FileReader und BufferedReader to read the file.

public static void main(String[] args) throws Exception{
   FileInputStream fr = new FileInputStream("README.TXT");
   BufferedReader br = new BufferedReader(new InputStreamReader(fr,"UTF-8"));
   String s="";
   while((s=br.readLine())!=null){
      System.out.println(s);
    }
}

但输出为: \ u0032 \ u0142o \ u017Cy \ u0142

我用的时候

System.out.println("\u0032\u0142o\u017Cy\u0142");

这些代码将被解析并以正确的形式显示。

These codes will be parsed and will be shown in the right form.

如何更改我的代码,以便文件中的unicode也会被解析并以正确的形式显示?

How can I change my code, so that unicode from the files will also be parsed and shown in the right form?

推荐答案

您可以使用发布的源代码这里做unescaping。

You can use the source code posted here to do unescaping.

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

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