1. 程式人生 > >node 讀取cav 異常編碼簡介

node 讀取cav 異常編碼簡介

var iconv = require('iconv-lite');
var fileStr = fs.readFileSync(‘xxx.csv’, { encoding: 'binary' }); var buf = new Buffer(fileStr, 'binary'); var str = iconv.decode(buf, 'GBK'); var data = str.toString(); var table = new Array(); var rows = new Array(); rows = data.split("\n"); for (var i = 0; i < rows.length; i++) { table.push(rows[i].split(",")); } return table;