fs_test.js 377 B

12345678910111213141516171819
  1. const fs = require('fs')
  2. const filepath = './tempfil.txt'
  3. const fileContent = '测试内容....'
  4. // 回调写入文件
  5. fs.writeFile(filepath, fileContent, (err) => {
  6. console.log(err)
  7. });
  8. fs.readFile(filepath, {encoding: 'utf-8'}, (err, data) => {
  9. if(err) {
  10. console.log(err)
  11. }
  12. else {
  13. console.log(data) // 输出 buffer 十六进制
  14. }
  15. })