在 Node.js 中,我想读取一个文件,然后 console.log()
文件的每一行由 \n
分隔。我该怎么做?
最佳答案
试试这个:
var fs=require('fs');
fs.readFile('/path/to/file','utf8', function (err, data) {
if (err) throw err;
var arr=data.split('\n');
arr.forEach(function(v){
console.log(v);
});
});
关于javascript - 如何在 Node.js 中读取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7224935/