我正在使用以下代码在节点中逐行读取文件:
const readInterface = readline.createInterface({
input: fs.createReadStream('/path/to/file'),
output: process.stdout,
console: false
});
readInterface.on('line', function(line) {
console.log(line);
if(i == 1) photoNumber = line;
if(i == 2) imgFolder = line;
if(i == 3) timeString = line;
i++;
});
这是我在终端中得到的输出:
3
3
/home/eugen/Pictures/wallpapers
/home/eugen/Pictures/wallpapers
[10 20], [14 50], [18 32][10 20], [14 50], [18 32]
因此,由于某种原因,内容翻了一番。我怎样才能避免这种情况?另外,我观察到某些命令不会使屏幕上的某些内容加倍。例如,使用
rl.question("\nDo you want to reset the saved data? (y/n): ", r => {
if(r.toLocaleLowerCase() == 'yes' || r.toLocaleLowerCase() == 'y') readData_();
});
在第三个 if 将导致第三行不加倍:[10 20], [14 50], [18 32]
慕森卡
qq_花开花谢_0
随时随地看视频慕课网APP
相关分类