First install the iconv-lite module
npm install iconv-lite
// Load the File System read and write module
var fs = require('fs');
// Load the encoding conversion module
var iconv = require('iconv-lite');
var file = "F:\\nodeJS\\app\\file\\input.txt";
readFile(file);
function readFile(file){
fs.readFile(file, function(err, data){
if(err)
console.log ("Read file fail " + err);
else{
// When read successfully
// output byte array
//console.log(data);
// Convert array to gbk Chinese
var texts = iconv.decode(data , 'gbk');
console.log(texts);
}
});
}
-------------------------------Key question
// Convert the array to gbk Chinese
iconv.decode(data, 'gbk ');
Nodejs read file Chinese garbled utf8 to gbk solution
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326664605&siteId=291194637
Recommended
Ranking