nodejs fs模块读取文件
var fs = require("fs"); var readStream = fs.createReadStream(path, {'encoding':'utf8'}); var bufferData = [], size = 0; readStream.on('data', function(chunk){// typeof chunk "string" bufferData.push(new Buffer(chunk)); size += chunk.length; }); readStream.on('end', function(){ var bufferResult = Buffer.concat(bufferData, size); console.log(bufferResult.toString());});