特别异样的问题。我以为是我C盘安装问题。所以我放到了C盘的根目录
普通直接读取一个中文应该是这样的
const fs = require("fs")
fs.readFile("./a.txt", function(err, data){
if (err) throw err
console.log(data)
})
我就用正常方式填写了utf-8!并且将txt格式替换成UTF-8
const fs = require("fs")
fs.readFile("./a.txt", "utf8", function(err, data){
if (err) throw err
console.log(data)
})
问题就是他乱码居然只乱第一个。两个我都试了
不管是中文还是字母数字。都是第一乱码。
这是为什么呢?
建议不要使用记事本,它会自动给你加上 BOM(EF BB BF),换个高级点的编辑器(VSCode)就好了,详见 How can I make Notepad to save text in UTF-8 without the BOM?