4
【踩坑】Java输出文本到文件时乱码
source link: https://loli.fj.cn/2023/03/17/Java%E8%BE%93%E5%87%BA%E6%96%87%E6%9C%AC%E5%88%B0%E6%96%87%E4%BB%B6%E6%97%B6%E4%B9%B1%E7%A0%81/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
【踩坑】Java输出文本到文件时乱码
2023-03-17
Java输出文本到文件时乱码
- Windows95默认字符编码为GB2312,旧版本Windows10及以下版本默认字符编码为GBK,繁体中文字符编码为BIG-5,而在Linux/MacOS上的默认编码时UTF-8
- 将输出流输出的文本字符编码集改为GBK即可
Writer writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(file),
"GBK"
)
);
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK