码迷,mamicode.com
首页 > Web开发 > 详细

nodejs写文件

时间:2017-08-27 12:00:15      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:ejs   node   txt   adf   save   fun   UI   efi   读取   

var fs = require(‘fs‘);
2 var txt = "以上程序使用fs.readFileSync从源路径读取文件内容,并使用fs.writeFileSync将文件内容写入目标路径。";

fs.writeFileSync(‘message.txt‘, ‘Hello Node‘); //同步写法,默认utf-8
fs.writeFileSync(‘message.txt‘, ‘Hello Node‘,‘utf-8‘);


//写入文件
fs.writeFile(‘message.txt‘, txt, function (err) {
if (err) throw err;
console.log(‘It\‘s saved!‘); //文件被保存
});

10 //读取文件
11 fs.readFile(‘message.txt‘, ‘utf8‘, function (err, data) {
12 if (err) throw err;
13 console.log(data);
14 });

nodejs写文件

标签:ejs   node   txt   adf   save   fun   UI   efi   读取   

原文地址:http://www.cnblogs.com/yu-hailong/p/7439861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!