C 之txt的資料寫入

2021-09-27 07:18:31 字數 581 閱讀 5959

小夥伴們在使用c#開發時,可能需要將一些資訊寫入到txt,這裡就給大家介紹幾種常用的方法。

string

lines =

;system.io.file.

writealllines

(@"想儲存的位置\writelines.txt"

, lines)

;

string text =

"這是第一行"

+"\r\n"

+"這是第二行 "

;system.io.file.

writealltext

(@"想儲存的位置\writelines.txt"

, text)

;

string

lines =

;using

(system.io.streamwriter file =

newsystem.io.streamwriter

(@"想儲存的位置\writelines.txt"

,false))

}

C 寫入資料到txt檔案

string readme readme.txt 檔名稱 string txtpath path readme 檔案存放路徑 directoryinfo directoryinfo new directoryinfo path if directoryinfo.exists 判斷 資料夾是否存在 i...

C 寫入txt 檔案

filestream fs new filestream c s.txt filemode.create,fileaccess.write streamwriter sw new streamwriter fs sw.basestream.seek 0,seekorigin.begin for in...

C 檔案操作(向 txt檔案寫入資料)

本文講解的是向.exe同一目錄下的data資料夾下的log.txt寫入資料。假若.exe所在路徑是e projects logout log debug。1.1向上一級目錄指向 表示當前路徑,相當於e projects logout log debug 表示當前路徑的上一級路徑,相當於e proje...