node.js - 如何在 Node.js 中设置文件编码

我在 node.js 中设置编码时遇到了一些问题。 我尝试使用 writeFile 函数将编码设置为 utf8。 但没有结果。我想使用 node.js 设置编码的当前文件是用 unicode 编码的。

最佳答案

By default, the fs module will write files with an encoding of 'utf8'. UTF-8 is an encoding commonly used in web pages and other documents. File encoding refers to the character set that is used for the contents of the file. Commonly used encodings are 'utf8', 'ascii', 'binary', 'hex', 'base64' and 'utf16le'.

来源自stackabuse .

写入带编码的文件

如果options 是一个字符串,那么它指定编码。示例:

fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);

或者 options 是一个对象,

fs.writeFile('message.txt', 'Hello Node.js', {encoding: 'utf8'}, callback);

检查 here了解更多信息

https://stackoverflow.com/questions/46175144/

相关文章:

scala - 为什么我不能在 Scala 中增加?

python - Python 中的 str.join() 和 str().join() 有什么区别

oauth - 我如何测试是否已获得管理员同意

php - 为什么 Google_Service_Drive 文件的属性只返回 null?

javascript - 如何在 Gatsby.js 中将时间戳附加到 markdown 前面的内容

css - 通过添加元素 React.js 的数量来更改 div 元素的高度

apache-spark-sql - pySpark groupby 中的条件聚合

python - 无法将字节连接到 str(转换为 Python3)

amazon-web-services - aws s3 ls 递归 grep 扩展 '.mov'

julia - 如何更改 Julia 中的最大递归深度?