gpt4 book ai didi

linux - 使用变音符号导出 CSV 会导致输出中出现奇怪的字符

转载 作者:太空宇宙 更新时间:2023-11-04 04:04:51 25 4
gpt4 key购买 nike

我在 Scala/Spray 中导出了 csv,它在我的 Windows 计算机上运行良好,但在 Linux 计算机上失败。

两个操作系统的响应是相同的:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:X-Requested-With, Cache-Control, Pragma, Origin, Authorization, Content-Type, Auth-Token
Access-Control-Allow-Methods:GET, POST, DELETE, OPTIONS, PUT
Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:Auth-Token
Content-Disposition:attachment; filename=Enter report title.csv
Content-Length:229
Content-Type:text/csv; charset=ISO-8859-1
Date:Fri, 07 Feb 2014 22:17:40 GMT
Server:spray-can/1.2.0

我想知道为什么操作系统可以有所作为?

部署 jar 后从 Linux 导出时,变音符号会被奇怪的字符替换。

例如这个玛奇朵咖啡厅
从 Windows 导出时没问题,但看起来像 Café macchiato
从 Linux 导出时。

最佳答案

为了帮助 Excel 识别字符编码,您可以添加 BOM到文件的开头。例如:

def prepareBomOutputStream(outputFile: String) = {
val os = new FileOutputStream(outputFile)
os.write(239)
os.write(187)
os.write(191)
os
}

您还可以检查在这两种情况下是否获得完全相同的编码而不是编码的子集。例如,在 Windows 上,您可能会得到 ISO-8859-15。您很可能可以在 CSV 导出代码/库中显式设置编码。要检查 Linux 上的编码,您可以使用:

$ file -ib /tmp/test.csv 
text/plain; charset=utf-8

或者甚至像hexdump之类的东西。

关于linux - 使用变音符号导出 CSV 会导致输出中出现奇怪的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21639018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com