- 基础函数3:操作完成后,选择后续操作
*/
function choice() {
readLine(‘返回主界面请按x,退出请按e:’, answer => {
if (answer === ‘x’) {
showMenu();
} else if (answer === ‘e’) {
exit();
} else {
console.log(‘输入有误,程序结束’)
exit();
}
})
}
/**
- 记录创建
*/
function createFile() {
getSaveContent((content) => {
// 1. 打开文件
fs.open(filesPath + /${new Date().getTime()}.txt
, ‘w’, (err, fd) => {
if (!err) {
// 2. 写入文件
fs.writeFile(fd, content, (err) => {
if (!err) {
console.log(写入文件成功
);
} else {
throw err;
}
});
// 3. 关闭文件
fs.close(fd, (err) => {
if (!err) {
console.log(文件已经保存并关闭!
);
choice();
} else {
throw err;
}
})
}
});
});
}
/**
- 全体查询
*/
function searchAllFiles() {
getAllFiles(files => {
let length = files.length;
for (let i = length - 1; i >= 0; i–) {
console.log(文件${length - i}:${files[i]}
)
}
choice();
})
}
/**
- 关键词查询
*/
function searchAllFilesTitle() {
getAllFiles(files => {
let length = files.length;
for (let i = length - 1; i >= 0; i–) {
fs.readFile(filesPath + /${files[i]}
, (err, data) => {
if (!err) {
let dataString = data.toString();
let dataJson = JSON.parse(dataString);
console.log(文件${length - i}名称,${files[i]},标题:${dataJson.title}
)
}
if (i === 0) {
choice();
}
});
}
})
}
/**
-
根据序号查询记录的详细内容
-
@param order 序号
*/
function searchFileContent(order) {
getAllFiles(files => {
let length = files.length;
fs.readFile(filesPath + /${files[length - order]}
, (err, data) => {
if (!err) {
let dataString = data.toString();
let dataJson = JSON.parse(dataString);
console.log(文件${length - order}名称,${files[length - order]},详细内容:${dataJson.content}
)
choice();
} else {
choice();
}
});
})
}
/**
-
根据序号删除记录
-
@param order 序号
*/
function deleteFile(order) {
getAllFiles(files => {
let length = files.length;
fs.unlink(filesPath + /${files[length - order]}
, (err, data) => {
if (!err) {
console.log(文件${files[length - order]}删除成功!
)
choice()
} else {
choice()
}
});
})
}
/**
- 退出程序
*/
function exit() {
console.clear();
console.log(‘欢迎下次使用’);
process.exit()
}
/**
- 显示菜单
*/
function showMenu() {
// 1. 清空控制台
console.clear();
process.stdout.write(‘\033[2J’);
process.stdout.write(‘\n’);
// 2. 输入选择条件
console.log(
`********************************
请输入操作名称
C:记录创建
S:全体查询
K:关键字查询
T:查询记录的详细内容
D:删除记录
E:退出记事本应用
*********************************`);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(‘请选择你的操作:’, answer => {
switch (answer.toUpperCase()) {
case ‘C’:
console.clear();
createFile();
break;
case ‘S’:
searchAllFiles();
break;
case ‘K’:
searchAllFilesTitle();
break;
case ‘T’:
readLine(‘输入格式:v1.请输入查询内容:’, answer => {
searchFileContent(Number(answer.substring(1)));
})
break;
case ‘D’:
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
img-nTQUWqq9-1715234534070)]
[外链图片转存中…(img-RLKLkpti-1715234534070)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!