标签:
var fs = require(‘fs‘);
fs.readFile(‘./test.txt‘,function(err,data){
if(err){
console.log(‘err‘);
}else{
console.log(data);
}
});
var fs = require(‘fs‘);
var data = ‘测试数据‘;
fs.writeFile(‘./write.txt‘,data,function(err){
if(err){
console.log(‘err‘);
}else{
console.log(‘ok‘);
}
});
var fs = require(‘fs‘);
fs.open(‘./test.txt‘,‘r‘,function(err,fd){
var buf = new Buffer(255);
fs.read(fd,buf,0,9,3,function(err,bytesRead,buffer){
if(err){
console.log(‘err‘);
}else{
console.log(buffer.slice(0,bytesRead).toString());
}
});
});
var fs = require(‘fs‘);
var buffer = new Buffer(‘hello world‘);
fs.open(‘./test.txt‘,‘w‘,function(err,fd){
fs.write(fd,buffer,0,9,3,function(err,written,buffer){
if(err){
console.log(‘err‘);
}else{
console.log(‘ok‘);
}
});
});
var fs = require(‘fs‘);
fs.mkdir(‘./test‘,function(err){
});
fs.readdir(‘./test‘,function(err,files){
});
fs.stat(‘./test‘,function(err,stats){
});
fs.lstat(‘./test‘,function(err,stats){
});
fs.exists(‘./test‘,function(exists){
});
fs.realpath(‘./test‘,function(err,resolvedPath){
});
fs.utimes(‘./test.txt‘,new Date(),new Date(),function(err){
});
fs.chmod(‘./test.txt‘,0740,function(err){
});
fs.rename(‘./test.txt‘,‘./copy.txt‘,function(err){
});
fs.link(‘./test.txt‘,‘./link.txt‘,function(err){
});
fs.unlink(‘./link.txt‘,function(err){
});
fs.symlink(‘./test.txt‘,‘./link.txt‘,‘dir‘,function(err){
});
fs.readlink(‘./link.txt‘,function(err){
});
fs.truncate(‘./test.txt‘,10,function(err){
});
fs.rmdir(‘.test‘,function(err){
});
var fun = function(curr,prev){
}
fs.watchFile(‘./test.txt‘,fun);
fs.unwatchFile(‘./test.txt‘,fun);
var fs = require(‘fs‘);
var file = fs.createReadStream(‘./test.txt‘);
file.on(‘open‘,function(fd){
console.log(‘open‘);
});
file.on(‘data‘,function(data){
console.log(‘data‘);
});
file.on(‘end‘,function(){
console.log(‘end‘);
});
file.on(‘close‘,function(){
console.log(‘close‘);
});
file.on(‘error‘,function(err){
console.log(‘error‘);
});
var fs = require(‘fs‘);
var out = fs.createWriteStream(‘./test.txt‘);
console.log(‘open‘);
});
});
});
var fs = require(‘fs‘);
var file = fs.createReadStream(‘./test.txt‘);
var out = fs.createWriteStream(‘./out.txt‘);
file.pipe(out);
var path = require(‘path‘);
path.normalize([path]); //转化为标准路径
path.join([path],[path1],...); //合并字符串
path.resolve(path,[path1],...); //以应用程序跟目录为起点,根据所有的字符串合并成一个绝对路径
path.relative(from,to); //获取两个路径的相对路径
path.dirname(path); //获取一个路径的目录名
path.basename(path); //获取一个路径的文件名
path.extname(path); //获取一个路径的扩展名
path.sep //获取系统指定的文件分隔符 windows "\\"
path.delimiter //获取系统指定的路径分隔符 windoes ":"
标签:
原文地址:http://www.cnblogs.com/SLchuck/p/4909442.html