我在 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/
相关文章:
python - Python 中的 str.join() 和 str().join() 有什么区别
php - 为什么 Google_Service_Drive 文件的属性只返回 null?
javascript - 如何在 Gatsby.js 中将时间戳附加到 markdown 前面的内容
css - 通过添加元素 React.js 的数量来更改 div 元素的高度
apache-spark-sql - pySpark groupby 中的条件聚合
python - 无法将字节连接到 str(转换为 Python3)