node.js fs所有函數的定義和功能

來源:互聯網
上載者:User

標籤:style   os   io   檔案   時間   res   type   ad   

表4-1 fs 模組函數表

功能 非同步方法呼叫 同步方法
開啟檔案  fs.open(path,flags, [mode], [callback(err, fd)])  fs.openSync(path, flags, [mode])
關閉檔案  fs.close(fd, [callback(err)])  fs.closeSync(fd)
讀取檔案(檔案描述符 )fs.read(fd,buffer,offset,length,position, [callback(err, bytesRead, buffer)])  fs.readSync(fd, buffer, offset, length, position) 
寫入檔案(檔案描述符) fs.write(fd,buffer,offset,length,position, [callback(err, bytesWritten, buffer)])  fs.writeSync(fd, buffer, offset, length, position) 
讀取檔案內容  fs.readFile(filename,[encoding],[callback(err, data)])  fs.readFileSync(filename, [encoding]) 
寫入檔案內容  fs.writeFile(filename, data,[encoding], [callback(err)])  fs.writeFileSync(filename, data, [encoding]) 
刪除檔案  fs.unlink(path, [callback(err)])  fs.unlinkSync(path) 
建立目錄  fs.mkdir(path, [mode], [callback(err)])  fs.mkdirSync(path, [mode]) 
刪除目錄  fs.rmdir(path, [callback(err)])  fs.rmdirSync(path) 
讀取目錄  fs.readdir(path, [callback(err, files)])  fs.readdirSync(path) 
擷取真實路徑  fs.realpath(path, [callback(err, resolvedPath)])  fs.realpathSync(path)
更名  fs.rename(path1, path2, [callback(err)])  fs.renameSync(path1, path2) 
截斷  fs.truncate(fd, len, [callback(err)]) fs.truncateSync(fd, len)   
更改所有權  fs.chown(path, uid, gid, [callback(err)])  fs.chownSync(path, uid, gid) 
更改所有權(檔案描述符) fs.fchown(fd, uid, gid, [callback(err)])  fs.fchownSync(fd, uid, gid) 
更改所有權(不解析符號連結) fs.lchown(path, uid, gid, [callback(err)])  fs.lchownSync(path, uid, gid) 
更改許可權  fs.chmod(path, mode, [callback(err)])  fs.chmodSync(path, mode) 
更改許可權(檔案描述符) fs.fchmod(fd, mode, [callback(err)])  fs.fchmodSync(fd, mode) 
更改許可權(不解析符號連結) fs.lchmod(path, mode, [callback(err)])  fs.lchmodSync(path, mode) 
擷取檔案資訊  fs.stat(path, [callback(err, stats)])  fs.statSync(path) 
擷取檔案資訊(檔案描述符) fs.fstat(fd, [callback(err, stats)])  fs.fstatSync(fd) 
擷取檔案資訊(不解析符號連結) fs.lstat(path, [callback(err, stats)])  fs.lstatSync(path) 
建立永久連結 fs.link(srcpath, dstpath, [callback(err)])   fs.linkSync(srcpath, dstpath) 
建立符號連結  fs.symlink(linkdata, path, [type], [callback(err)])  fs.symlinkSync(linkdata, path, [type]) 
讀取連結  fs.readlink(path, [callback(err, linkString)])  fs.readlinkSync(path) 
修改檔案時間戳記  fs.utimes(path, atime, mtime, [callback (err)])  fs.utimesSync(path, atime, mtime) 
修改檔案時間戳記(檔案描述符) fs.futimes(fd, atime, mtime, [callback (err)])  fs.futimesSync(fd, atime, mtime) 
同步磁碟緩衝  fs.fsync(fd, [callback(err)])  fs.fsyncSync(fd)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.