nodejs fs.readFile

fs.readFile(path[, options], callback)

 

 

 

 

 

 

demo 

02.js

var fs=require("fs");


fs.readFile('test.txt',function (err,data) {
    if (err ) {
        console.log("读取失败")
    } else {
        //输出test.txt的内容
        console.log(data.toString());
    }


});

test.txt

 how are you 
  you are good

输出结果:

 

posted @ 2017-11-05 18:50  1点  阅读(443)  评论(0编辑  收藏  举报