世界上最伟大的投资就是投资自己的教育
-
const fs = require('fs');
const mkdir = function (dirname) {
return new Promise(function (resolve, reject) {
fs.mkdir(dirname,()=>{
resolve();
});
});
};
const readFile = function (fileName) {
return new Promise(function (resolve, reject) {
fs.readFile(fileName, function(error, data) {
if (error) return reject(error);
resolve(data);
});
});
};
const writeFile = function (fileName,data) {
return new Promise(function (resolve, reject) {
fs.writeFile(fileName,data,()=>{
resolve(1);
})
});
};
const asyncReadFile = async function () {
const f1 = await mkdir('stuff');
const f2 = await readFile('./abc.txt');
const f3 = await writeFile('./stuff/abc_copy.txt',f2);
};
asyncReadFile().then((d)=>{
console.log('copy success);
})这样好一点
© 汕尾市求知科技有限公司 | Rails365 Gitlab | 知乎 | b 站 | csdn
粤公网安备 44152102000088号 | 粤ICP备19038915号
Top