Node.js fs set read stream encoding

Description

Node.js fs set read stream encoding


var fs = require("fs");
var data = ''

var readStream = fs.createReadStream('input.txt');

readStream.setEncoding('UTF-8');

readStream.on('data',function(chunk){
  data += chunk;/*  ww w .  j  a  v  a 2s.c o  m*/
});

readStream.on('end',function(){
  console.log(data);
});

readStream.on('error',function(err){
  console.log(err.stack);
});



PreviousNext

Related