使用`iConv'从UTF-16LE到UTF-8转换文件,得出UTF-16LE文件

发布于 2025-01-24 09:04:00 字数 406 浏览 3 评论 0 原文

标题。

我运行的命令是:

iconv -f UTF-16LE -t UTF-8 .\data\schema-utf16le.graphql > .\data\schema-utf8.graphql;

但是,生成的文件 schema-utf8.graphql 仍然是 utf-16le 编码。

我在做什么错?

我在Windows上,

Title.

The command I run is:

iconv -f UTF-16LE -t UTF-8 .\data\schema-utf16le.graphql > .\data\schema-utf8.graphql;

However, the generated file schema-utf8.graphql is still UTF-16LE encoded.

What am I doing wrong?

I am on windows and installed this version of iconv.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笙痞 2025-01-31 09:04:00

这个问题已经在线很长时间了,实际上没有任何意见和答案。这是我最终解决问题的方法。

我为nodejs制作了一个执行转换的脚本:

const fs = require('fs');

const schemaFileName = 'data/schema.graphql';

const readContent = fs.readFileSync(schemaFileName, {
  encoding: 'utf16le',
});

const writeContent = (readContent.charAt(0) === '\ufeff')
  ? readContent.substring(1)
  : readContent;

fs.writeFileSync(schemaFileName, writeContent, 'utf8');

This question has been online for a long time and received literally no views nor an answer. Here's how I finally solved the problem.

I made a script for nodejs which performs the conversion:

const fs = require('fs');

const schemaFileName = 'data/schema.graphql';

const readContent = fs.readFileSync(schemaFileName, {
  encoding: 'utf16le',
});

const writeContent = (readContent.charAt(0) === '\ufeff')
  ? readContent.substring(1)
  : readContent;

fs.writeFileSync(schemaFileName, writeContent, 'utf8');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文