C 高階學習第十七天

2021-09-13 14:18:43 字數 2719 閱讀 4460

2 fileinfo類

3 directory類

絕對路徑:string path = 「/users/neworigion/desktop/a.txt」;

相對路徑: b.txt」; 當前目錄是當前程式生成的可執行檔案的目錄

file.create(path);

file.delete(path);

對檔案內容的一種資料快取,

建立檔案時,會自動生成乙個檔案流,刪除前,要先刪除檔案流

filestream fs = file.create(path); fs.close();

file.exists(path);

file.copy(path,path2,true);

只有2個引數,重複則丟擲異常,相當於刪除,

移動前注意檔案流的關閉

file.move(path,path2);

filestream fs = null;

fs = file.open (path2, filemode.open);

string s = " hello";                         aaaaabbbbbccccc

byte b = encoding.default.getbytes (s); //將字串轉換為byte陣列

fs.write (b, 0, b.length); hellobbbbbccccc

// byte st = new byte[100];

byte st = encoding .default .getbytes("00000000000");

fs.read (st, 0, 5); //讀取資料,並儲存到陣列中

//第二個引數:向陣列中寫入的位置

string ss = encoding.default.getstring (st); //byte陣列轉換為string //結果為:bbbbb

fs.flush ();

fs.close();

//剛建立的檔案流位置指向檔案的開頭

//對檔案流操作後,檔案流的位置跟著向後移

fs.seek(0,seekorigin.begin);

seekorigin 是列舉型別

begin 檔案開頭

current 當前檔案流的位置

end 檔案的結尾

//streamwriter  和  streamreader

streamwriter sw = new streamwriter (fs); //通過fs建立乙個專門進行寫操作的流

sw.write ("aaaaa"); //原來的內容將會被替代 a.txt bbbbbbbbbb

sw.flush (); //aaaaabbbbb

sw.write ("0000a"); //aaaaa0000a

sw.flush ();

fs.seek (0, seekorigin.begin);

streamreader sr = new streamreader (fs);

string str = sr.readtoend(); //直接讀到尾

console.writeline (str);

sw.close ();

sr.close ();

fs.close (); //只有fs.close ();也可

fileinfo中的方法都是例項方法,要通過物件呼叫方法

fileinfo fi = new fileinfo (path);

filestream fs = fi.create (); fs.close()

fi.moveto(path2);

fi.copyto(path2);

fi.delete(path);

fi.exists(path);

路徑 string path2 = 「/users/neworigin/desktop/bb」;

string path3 = 「/users/neworigin/desktop/cc/」;

directory.createdirectory (path);

非空則設定為true

directory.delete (path,true);

directory.move (path, path2);

string paths = directory.getfiles (path2,」*」, searchoption.topdirectoryonly); 

foreach (string item in paths) //預設當前目錄下查詢

// searchoption.alldirectories

foreach (string item in paths)

string t = directory.getcurrentdirectory();

directoryinfo f = directory.getparent(t);

Python學習 第十七天

在下這廂有禮了 練習 python修改檔案時,使用w模式會將原本的檔案清空 覆蓋。可以先用讀 r 的方式開啟,寫到記憶體中,然後再用寫 w 的方式開啟。yesterday when i was young 昨日當我年少輕狂 the taste of life was sweet 生命的滋味是甜的 a...

linux學習第十七天

18.1 資料庫管理系統 資料庫是指按照某些特定結構來儲存資料資料的資料倉儲。在當今這個大資料技術迅速崛起的年代,網際網路上每天都會生成海量的資料資訊,資料庫技術也從最初只能儲存簡單的 資料的單一集中儲存模式,發展到了現如今儲存海量資料的大型分布式模式。在資訊化社會中,能夠充分有效地管理和利用各種資...

打卡第十七天

第二次了,又沒過.有時候會有一種失敗感,這幾年好像什麼都沒做好,過的好像也不是很開心。昨天兵查過成績後心情就低落起來了,尤其是聽到晨晨得知她沒過時發出的驚訝聲音 你竟然沒過?時,心情立馬跌到了谷底,回到宿舍就再也繃不住了,大哭了一場,媽媽打 詢問情況,看到女兒哭的傷心,竟也無措起來,不知如何安慰。於...