标签:
一、打开和关闭文件 //在不同的操作系统中表现有所不同
附:flags参数表,表示打开文件的模式
‘r+‘
- Open file for reading and writing. An exception occurs if the file does not exist.
‘rs+‘
- Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache.
This is primarily useful for opening files on NFS mounts as it allows you to skip the potentially stale local cache. It has a very real impact on I/O performance so don‘t use this flag unless you need it.
Note that this doesn‘t turn fs.open()
into a synchronous blocking call. If that‘s what you want then you should be using fs.openSync()
‘w‘
- Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
‘wx‘
- Like ‘w‘
but fails if path
exists.
‘w+‘
- Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
‘wx+‘
- Like ‘w+‘
but fails if path
exists.
‘a‘
- Open file for appending. The file is created if it does not exist.
‘ax‘
- Like ‘a‘
but fails if path
exists.
‘a+‘
- Open file for reading and appending. The file is created if it does not exist.
‘ax+‘
- Like ‘a+‘
but fails if path
exists.
二、写入文件
1、简单文件写入
fs.writeFile(fileName,data,[opations],callback)
2、同步文件写入
var fd=fs.opneSync(path,flags[,mode])
fs.writeSync(fd,buffer,offset,length[,position])
fs.writeSync(fd,data[,position][,encoding])
fs.closeSync(fd)
:
确定从哪个位置开始写入buffer。3、异步写入文件
4、流式文件写入
三、读取文件(同上)
1、简单文件读取
2、同步文件读取
3、异步文件读取
4、流式文件读取
四、其他文件系统任务
1、fs.stat(path, callback) //获取文件信息
stats.isDirectory() //如果条目是一个目录,返回true
stats.isBlockDevice() //
stats.isCharacterDevice() //
stats.isSymbolicLink()
(only valid with fs.lstat()) //stats.isFIFO() //
stats.isSocket() 如果条目是一个套接字,返回true
2、列出文件(列出path路径的所有子目录,以数组方式存储)
3、删除文件
4、截断文件
5、建立和删除目录
6、重命名文件和目录
7、监视文件更改入
标签:
原文地址:http://www.cnblogs.com/realsoul/p/5617123.html