C 之檔案 目錄的操作常見方法

2021-09-26 00:26:22 字數 3037 閱讀 2687

namespace _026_檔案操作_檢視檔案和資料夾資訊

"siki2.txt");//重新命名操作

//資料夾操作(目錄操作) (按照完整路徑名建立)

//directoryinfo dirinfo = new directoryinfo(@"c:\users\devsiki\documents\visual studio 2012\projects\學習csharp程式設計 高階篇\026-檔案操作-檢視檔案和資料夾資訊\bin\debug");//檢視debug資料夾的資訊

"siki");

//directoryinfo dirinfo = new directoryinfo("test");

//if (dirinfo.exists == false)

// console.

readkey()

;}}}

使用file讀寫檔案

using system;

using system.collections.generic;

using system.io;

using system.linq;

using system.text;

using system.threading.tasks;

namespace _027_使用file讀寫檔案

//string s = file.readalltext("textfile1.txt");

//byte bytearray = file.readallbytes("3.linq.png");

//foreach (var b in bytearray)

//"textfile2.txt", "hello sdf中國");

"textfile3.txt",new string);

//複製

byte

data = file.

readallbytes

("3.linq.png");

file.

writeallbytes

("4.png"

,data)

; console.

readkey()

;}}}

使用filestream讀寫檔案(適合處理二進位制):

using system;

using system.collections.generic;

using system.io;

using system.linq;

using system.text;

using system.threading.tasks;

using system.xml;

namespace _028_使用filestream讀寫檔案

// for (int i = 0; i < length; i++)

//}//使用filestream完成檔案複製

// 1.5mb = 1.5*1024kb = 2k多kb= 2k多*1000 byte

filestream readstream =

newfilestream

("3.linq.png"

,filemode.open)

;filestream writestream =

newfilestream

("linq副本.png"

,filemode.create)

;byte

data =

newbyte

[1024];

while

(true

)else

} writestream.

close()

; readstream.

close()

;

console.

readkey()

;}}}

using system;

using system.collections.generic;

using system.io;

using system.linq;

using system.text;

using system.threading.tasks;

namespace _029_使用streamreader和streamwriter讀寫文字檔案

//string str = reader.readtoend();//讀取到文字的結尾(讀取文字中所有的字元)

//while (true)

//// else

//

//}//文字檔案寫入流

streamwriter writer =

newstreamwriter

("textfile2.txt");

//如果檔案存在,那麼檔案會被覆蓋

while

(true

) writer.

close();}

Python os的常見方法

1 os.getcwd filename 相當於在當前執行檔案的目錄下建立乙個以filename命名的檔案 2 os.path.realpath file 獲取當前檔案路徑 c users admin pycharmprojects test case test unitest.py file 表示...

JS常見方法封裝之陣列

接之前的字串常用方法封裝,這裡是陣列型別。在此之前你還需要掌握一些js原生的字串api。length設定或返回陣列中元素的數目 concat 連線兩個或更多的陣列,並返回結果。join 把陣列的所有元素放入乙個字串,元素通過指定的分隔符進行分隔。注釋 預設使用逗號作為分隔符 push 向陣列的末尾新...

C語言結構體的常見方法

什麼是結構體?在c語言中,結構體 struct 指的是一種資料結構,是c語言中聚合資料型別 aggregate data type 的一類。結構體可以被宣告為變數 指標或陣列等,用以實現較複雜的資料結構。結構體同時也是一些元素的集合,這些元素稱為結構體的成員 member 且這些成員可以為不同的型別...