c File類(寫入檔案)

2021-10-24 19:46:25 字數 1285 閱讀 4318

1、file.writeallbytes(string path, content)

建立乙個新檔案,寫入指定的位元組陣列,與filereadallbytes() 相反,如果目標檔案已經存在,則會覆蓋目標檔案。

// system.text.encoding.utf8.getbytes(content) 把字串轉位元組陣列

2、file.writealllines(string path, string[ ])建立乙個新檔案,寫入指定的字串陣列,與filereadallbyt

console.writeline("寫入成功!");

3、file.writealltext(string path, string contens)建立乙個新檔案,寫入指定的字串,如果目標檔案已存在,則覆蓋檔案。

建立乙個新檔案,向其追加指定的字串,如果目標已存在,則會開啟檔案向其追加指定字串。

小練習:

static void main(string args)

CFile建立檔案,寫入,寫入完畢

1.檔案建立 cfile m file m file.open sfilename,cfile modecreat cfile modewrite 第乙個引數是建立的檔案的名稱 第二個引數意義是建立檔案及建立乙個可寫的檔案 2.檔案的寫入 m file.write sdata,sdata.getle...

C File類 檔案操作

c 語言中 file 類同樣可以完成與 fileinfo 類相似的功能,但 file 類中也提供了一些不同的方法。file 類中獲取或設定檔案資訊的常用方法如下表所示。屬性或方法 作用datetime getcreationtime string path 返回指定檔案或目錄的建立日期和時間 dat...

MFC下用CFile類進行檔案的寫入

因為cfile類預設是英文寫入檔案,所以如果不設定的話是不會在檔案中寫入中文的。需要進行以下設定 需加標頭檔案 include 確保能讀寫中文 tchar old locale tcsdup tsetlocale lc ctype,null tsetlocale lc ctype,t chs 在cf...