https://blog.csdn.net/zhishiqu/article/details/79800570
npm install -g iconv-lite
准备一个文本文件(当然也可以是csv文件等)test.txt和text.csv,nodejs文件test.js如下:
var iconv = require('iconv-lite'); var fs = require('fs'); var fileStr = fs.readFileSync('D:\\test.csv', {encoding:'binary'}); var buf = new Buffer(fileStr, 'binary'); var str = iconv.decode(buf, 'GBK'); console.log(str);
转载请注明:有爱前端 » nodejs读取文件乱码问题