在 C# 中将文件另存为 Unicode 停止按预期工作

发布于 2025-01-15 04:42:17 字数 629 浏览 3 评论 0原文

我有编码为 UTF-8 的演示文件,其中包含特殊字符: 输入图片这里的描述

我有一个解决方案,将该文件转换为 Unicode(此转换是必要的,以便 MS Excel 正确显示数据):

 string fileContent = File.ReadAllText(inputFilePath, Encoding.Default);
    File.WriteAllText(outputFilePath, fileContent, Encoding.Unicode);

它在很长一段时间内工作正常,但突然停止工作。目前转换后数据显示为垃圾: 输入图片此处描述

我注意到数据现在保存为 UTF-16 LE。有什么想法导致这个问题吗?

I have demo file Encoded UTF-8, which includes special characters:
enter image description here

I had solution which was converting this file to Unicode (This conversion is necessary so data was displayed by MS Excel correctly):

 string fileContent = File.ReadAllText(inputFilePath, Encoding.Default);
    File.WriteAllText(outputFilePath, fileContent, Encoding.Unicode);

It worked just fine for a long time, but suddenly it stopped working. Currently after conversion data is displayed rubbish:
enter image description here

I've noticed that data is saved now as UTF-16 LE. Any ideas what is causing this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文