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()
}

})

猜你喜欢

转载自www.cnblogs.com/h5it/p/10177606.html