ITeye博客

nodejs 文件系统(fs) 之读写文件

cjx186 · 2014-01-25 23:01 · js、nodejs · 编程语言 · Markdown

var fs = require("fs");
//  
var data = '写入的的内容'; 
fs.writeFile('f:a.txt', data, 'ascii', function(err){
    if(err){ 
        console.log('写入文件失败'); 
    }else{
        console.log('保存成功');
        fs.readFile('f:a.txt','ascii', function(err, data){ 
            if(err){ 
                console.log('写入文件失败'); 
            }else{ 
				console.log('===读出来了==='+data); 
			} 
		});
 	}
});
//默认情况下,数据编码为utf8;mode=438 ;flag=w
// 在C盘创建一个名为a的文件夹 
fs.mkdir("c:a", function(err){ 
    if(!err){ 
        console.log("操作成功!");  
    }else{ 
        console.log("操作失败!"); 
    } 
});

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。