首页 > 解决方案 > java 8 写 utf-8 编码乱码

问题描述

我正在尝试获取一个有效的 utf-8 文本文件。通过工作,我的意思是它应该在 Firefox 和 libreoffice 中看起来正确。

写我使用:

PrintWriter writer = new PrintWriter(savepath, "UTF-8");

对于使用 java 阅读,我使用:

      InputStreamReader isr = new InputStreamReader(new FileInputStream(loadpath), Charset.forName("UTF-8"));
      BufferedReader br = new BufferedReader(isr);

再次阅读并在 java 中显示时,它是正确的。

使用 libreoffice 或 firefox(编码设置为 unicode)它会显示“乱码”字符。

示例文本:

C'est vrai   (Java) The french "That's true" is shown correct

Cest vrai  (firefox -set to unicode) the "'" becomes a square with "0092" inside

编辑:

CÂ’est vrai (firefox -set to middle european (windows) encoding)

编辑2:

writer.println("Cest vrai");
writer.flush();

https://imgur.com/a/CLL3eVK

编辑3:好的,我现在尝试了

writer.println("C"+"\u0092"+" est vrai");
writer.flush();

这导致(firefox 设置为 unicode): https ://imgur.com/qGRr9sC

在 libreoffice calc import 中,它看起来甚至有点不同(正方形为空): https ://imgur.com/MNQNDWo

标签: javautf-8

解决方案



推荐阅读