fs.readFile(path[, options], callback)
path
<string> | <Buffer> | <URL> | <integer> 文件名或文件描述符。options
<Object> | <string>encoding
<string> | <null> 默认为null
。flag
<string> 默认为‘r‘
。
callback
<Function>err
<Error>data
<string> | <Buffer>
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
原文地址:http://www.cnblogs.com/guangzhou11/p/7788198.html