node 读写文件

1. 文件目录

在这里插入图片描述

2. hello.txt
hello node.js
你好 node.js
3. index.js
var fs = require('fs');

fs.readFile('./hello.txt', function(error, data) {
    console.log(data.toString());
})
4. node执行

在这里插入图片描述

5. 写入文件

var fs = require('fs');

fs.writeFile('./hello.txt', 'hello javascript', function(error) {
    console.log(error)
});
发布了288 篇原创文章 · 获赞 50 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/gklcsdn/article/details/104026268