nodejs fs.readFile

Posted 1点

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

输出结果:

 

以上是关于nodejs fs.readFile的主要内容,如果未能解决你的问题,请参考以下文章