想读取一个密码字典,内容大概如下
//dic.txt
a
passw
passwo
password3
密码长度不同
//API上的例子
var fs = require('fs');
var path = "dic.txt";
var dic = fs.createReadStream(path);
var chunk
;
dic.on('readable', function() {
var chunk;
while (null !== (chunk = dic.read())) {
console.log('got %s ', chunk);
}
});
这样会把全部内容读出来,但是我想一行一行读的话
var fs = require('fs');
var path = "dic.txt";
var dic = fs.createReadStream(path);
var chunk
console.log(chunk=dic.read());
这要返回的却是null,这是为什么?