const fs=require('fs');

//文件名,写的内容,编码风格,调函数(如果出现错误,就要抛出)

fs.writeFile('./text','this is a test',{

encoding:'utf8'

},(err)=>{

if(err) throw err;

console.log('done!');

})

fs write

//也可以这默写编码格式

fs.writeFile('./text','this is a test','utf8',(err)=>{

if(err) throw err;

console.log('done!');

})

 

这写入的是字符串,那么如果写buffer的话,也可以忽略编码风格这一参数

const content = Buffer.from('this is a tasr 文本');

fs.writeFile('./text',content,(err)=>{

if(err) throw err;

console.log('done!');

})

fs write

相关文章:

  • 2022-03-08
  • 2021-06-24
  • 2021-12-24
  • 2021-12-15
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-26
  • 2021-08-27
  • 2021-05-10
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
相关资源
相似解决方案