java - 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();
编辑3:好的,我现在尝试了
writer.println("C"+"\u0092"+" est vrai");
writer.flush();
这导致(firefox 设置为 unicode): https ://imgur.com/qGRr9sC
在 libreoffice calc import 中,它看起来甚至有点不同(正方形为空): https ://imgur.com/MNQNDWo
解决方案
推荐阅读
- sqlite - 如何从 SQLite Query 中的某个时间戳中选择多个系列
- sql - PostgreSQL 性能:查询达到 52 周高点的股票(加入最大值行)
- android - FileProvider.getUriForFile 不会将图像保存到图库并且无法访问文件 OnActivityResult
- database - 列索引未反映在具有“IN”语句的谓词的解释计划中
- python - 如何在odoo中将树视图拆分为两列
- c# - Oxyplot - 编辑 LineSeries 中的左键单击标签
- performance - 使用 SIMD 会加载主 CPU 寄存器吗?
- python - 用opencv和python清理图像背景后如何正确提取字母?
- r - 要替换的项目数不是替换长度的倍数 + 同一图中的多个图错误
- acumatica - 通用查询作为主要列表/入口点