RT. I wrote three ways to read and write files, as follows:
fs.writeFile(filedir, field, function (err) {
if (err) {
console.log(err);
} else {
console.log("file done!");
}
});
fs.appendFile(filedir, , function (err) {
if (err) {
console.log(err);
} else {
console.log("catalog done!");
}
});
//
fs.readFile(fieldir, "utf8", (err, data) => {
....
now it"s like this. I save a piece of data in a new file at a time, then maintain a directory file, and then extract the file name of that corresponding file from the directory file and read the saved file. The problem is that every time the file is read before it is saved, the reading is completed, resulting in always reading the wrong file. Is there a way to make the read execute late, or is there any other way to make the three methods execute sequentially? Make sure you save it before you read it.