const util = require("util");
const fs = require("fs");
const path = require("path");
//获取你要写入的路径
const filePath = path.resolve(__dirname,"text.bat");
const result = new Promise((resolve,rejects)=>{
fs.readFile(filePath,(err,value)=>{
if(err){
rejects(err);
}
resolve(value.toString())
})
});
result.then((value)=>{
console.log(value.toString());
})
let util = require("util");
const fs = require("fs");
const path = require("path");
//返回一个新的函数,返回的结果就是Promise对象
const filePath = path.resolve(__dirname,"text.bat");
let result = util.promisify(fs.readFile);
result(filePath).then(value=>{
console.log(value.toString());
})
原文:https://www.cnblogs.com/Listener-wy/p/14851201.html