nodejs fs.readFile
fs.readFile(path[, options], callback)
path
<string> | <Buffer> | <URL> | <integer> 文件名或文件描述符。options
<Object> | <string>callback
<Function>
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
输出结果:
越努力越幸运