C 201801013關於檔案的操作

2021-08-29 01:15:33 字數 2163 閱讀 4949

建立乙個檔案流——filestream

建立讀取器或寫入器——streamreader/streamwriter

執行讀或者寫操作

關閉讀取器或寫入器

關閉檔案流

2、binaryreader和binarywriter類可用於讀寫二進位制檔案

這兩個類並不派生於stream,而是直接派生於system.object類

所有建立兩個類的物件必須基於所提供的派生於stream類的物件,如filestream類的物件

3、file類和fileinfo類——檔案基本操作

directory類和directoryinfo類——目錄基本操作

path類和enviroment類——路徑類和系統資訊類

4、當要讀取的檔案中包含漢字,需要指定編碼encoding.getencoding(「gb2312」)

string[ ] content=file.readalllines(path,encoding.getencoding(「gb2312」));

5、讀寫文字檔案

6、檔案基本操作

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

using system.io;

using microsoft.visualbasic.devices;

private void label1_click(object sender, eventargs e)

private void btncreate_click(object sender, eventargs e)

}catch(exception ex)

}private void btncopy_click(object sender, eventargs e)

catch(exception ex)

}private void btnrename_click(object sender, eventargs e)

catch (exception ex)

}private void btnmove_click(object sender, eventargs e)

else

}private void b***elete_click(object sender, eventargs e)

messagebox.show("檔案刪除成功!");

C 關於檔案的判斷

1 判斷檔案是否存在 判斷檔案是否存在,主要呼叫的是file.exists函式。private bool is exist string file path else 2 判斷檔案是否正在使用 判斷檔案是否正在使用主要使用的是乙個try catch 的使用,實際上在後續的使用中越來越感受到的是try...

關於C 檔案讀取

include include include include include define n 10000000 一千萬 int a n 1 void file 用於產生檔案的隨機數 void read cin void read scanf void read cin syn int main ...

c 關於new檔案

new檔案用來管理c 的動態記憶體,這個檔案宣告了幾個全域性空間的函式 不是std空間的函式,全域性空間的函式呼叫時是用全域性作用域解析符 包括operator new 和operator delete的過載 這些函式用於處理動態儲存空間請求。其new的標頭檔案源 ifndef new define...