nodejs fs 讀取檔案內容

2022-09-21 15:30:14 字數 818 閱讀 9340

-fs.readfile()

-用來讀取指定檔案的內容

-語法:fs.readfile(path,options,callback)

-path:必選引數,要讀取的檔案路徑

-options:可選引數,以什麼編碼格式來讀取檔案

-callback:必選引數,讀取檔案後,通過**函式拿到讀取的結果

-示例**:

const fs = require('fs')

fs.readfile('./file/1.txt','utf-8',function

(err,datastr))

-執行結果.jpg

-用來向指定檔案寫入內容

-語法:fs.readfile(path,data,options,callback)

-path:必選引數,要讀取的檔案路徑

-data:要寫入的內容

-options:可選引數,以什麼編碼格式來寫入內容

-callback:必選引數,讀取檔案後,通過**函式拿到讀取的結果

-示例**:

fs.writefile('./file/1.txt','寫入檔案的內容','utf-8',function

(err))

-執行結果.jpg  

nodejs fs模組 檔案操作

如果檔案不存在會自動建立檔案,存在則覆蓋。var fs require fs fs.writefile fs.txt hello nodejs utf8 function err console.log write file has been success var fs require fs if...

php 讀取檔案自身內容,與讀取檔案輸出內容

一,讀取檔案 先解釋一下,什麼是讀取檔案本身,什麼叫讀取檔案輸入內容。舉個例子test.php裡面的內容 1,讀取檔案本身就是讀取檔案內所有內容,讀取後就能得到 2,讀取檔案輸出內容是讀取檔案所表現出來的東西,讀取後得到test 二,fopen方法 1,讀取檔案本身 檢視複製列印?filename ...

C讀取檔案內容

include include include include include char getfilecontent const char psfilename int nfilelen lseek pf,0,seek end lseek pf,0,seek set char psfilecont...