使用java读取unicode文本文件 [英] Read unicode text files with java

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

问题描述

真正的简单问题。我需要在Java程序中读取Unicode文本文件。

Real simple question really. I need to read a Unicode text file in a Java program.

我习惯使用带有BufferedReader FileReader组合的纯ASCII文本,这显然不起作用:(

I am used to using plain ASCII text with a BufferedReader FileReader combo which is obviously not working :(

我知道我可以使用Buffered Reader以传统方式读取字符串,然后使用以下内容进行转换:

I know that I can read a String in the 'traditional' way using a Buffered Reader and then convert it using something like:

temp = new String(temp.getBytes(), "UTF-16");

但有没有办法将Reader包装在'转换器'中?

But is there a way to wrap the Reader in a 'Converter'?

编辑:文件以FF FE开头

the file starts with FF FE

推荐答案

你不会包装Reader,而是使用InputStreamReader包装流。
然后你可以包装使用您当前使用的BufferedReader

you wouldn't wrap the Reader, instead you would wrap the stream using an InputStreamReader. You could then wrap that with your BufferedReader that you currently use

BufferedReader in = new BufferedReader(new InputStreamReader(stream, encoding));

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

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