我使用NodeJS readline模块从文本文件中读取。它将每行返回到控制台,但是我希望它将返回的行添加到数组中。这是我到目前为止所获得的代码,但它不起作用。我认为rd.on充当了循环的一种,但它看起来并不像。任何帮助将不胜感激!
function getinfomation2(){
var firstfile = [];
var secondfile = [];
var countvar = 0;
readline = require('readline');
var rd = readline.createInterface({
input: fs.createReadStream('../FixtureProfiles/CFIP1.json'),
output: process.stdout,
terminal: false
});
// Add fixture details from file to array to later be called
rd.on('line', function(line) {
// if fails console.log(line) returns line in console
firstfile(countvar) = line;
console.log(firstfile(countvar))
countvar = countvar +1;
});
}
答案 0 :(得分:1)