Node.js fs文件系统模块

一、读取文件几个步骤
1.先引入fs文件系统模块
2.使用readfile 或
readFileSync 注意点:它们的回调函数有两个参数,第一个是err,第二个是data,得到的data是buffer文件,必须通过toString()方法转换一下

const fs = require('fs');

fs.readfile('./1.txt',function(err,data){
if(err){
 throw err;
}else{

  console.log(data.toString()
}

})
posted @ 2018-12-26 09:57  菜鸟程序员的总结  阅读(249)  评论(1)    收藏  举报