简体   繁体   English

如何从 Java 中具有 unicode 的文件中读取数据?

[英]How to read data from a file having unicode in Java?

I have a tsv file and it contains Unicode data like "Pär Lagerkvist's received Nobel Prize in Physics."我有一个 tsv 文件,其中包含 Unicode 数据,例如“Pär Lagerkvist 获得诺贝尔物理学奖”。 But while reading it in Java I am receiving output like "P r Lagerkvist's received Nobel Prize in Physics."但是在用 Java 阅读时,我收到了类似“P?r Lagerkvist 获得诺贝尔物理学奖”之类的输出

I am using the following piece of code for the file reading我正在使用以下代码进行文件读取

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
while ((st = br.readLine()) != null) {
    System.out.println(st);
}

I assume you are using Intellij Idea.我假设您正在使用 Intellij Idea。 This case, set console encoding这种情况,设置控制台编码

-Dfile.encoding=UTF-8

On Windows, edit idea.exe.vmoptions file and add the above line.在 Windows 上,编辑idea.exe.vmoptions文件并添加上面的行。

See this for details.有关详细信息,请参阅内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM