「node.js入門」createReadStream()の使い方

サンプルコード

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

// ストリームの作成
var readerStream = fs.createReadStream('data_enter.txt');

//  utf8を設定
readerStream.setEncoding('UTF8');

//  data, end, and error
readerStream.on('data', function(chunk) {
   data += chunk;
});

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

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

console.log("The program is executed");

JavaScript

Posted by arkgame