NodeJs以流的形式寫入文件

var fs = require("fs");
var data = "http://www.cewan.la phoenixframework自動化平臺";
var writerStream = fs.createWriteStream('output.txt');
writerStream.write(data,"UTF-8");
writerStream.end();
writerStream.on('finish', function() {
  console.log("寫入完成");
});
writerStream.on('error', function(err) {
  console.log(err.stack);
});
console.log("execute end...");

一、將以上代碼另存爲:writeStream.js,在當前目錄執行:node writeStream.jsjavascript

二、執行效果:java

相關文章
相關標籤/搜索