//1.引入fs 模块
var fs=require("fs")
//2.参数filePath代表传入的文件路径
function pReadFile(filePath){
return new Promise(function(resolve,reject){
//读取文件
//第一个参数代表读取文件失败,若失败,将参数err传入reject中
//第二个参数代表读取文件成功,data代表读取成功的数据,将参数data传入resolve中
fs.readFile(filePath,'utf8',function(err,data){
if(err){
reject(err)
}else{
resolve(data)
}
})
})
}
//then接收的是上一步return返回的数据
pReadFile('./a.txt')
.then(function(data){
console.log(data)
return pReadFile('./b.txt')
})
.then(function(data){
console.log(data)
})