黑馬程式設計師 File類

2021-06-22 19:35:05 字數 1209 閱讀 7265

---------------------- asp.net+unity開發、.net培訓、期待與您交流! ---------------------- 

file類使用

1、用來將檔案或者資料夾封裝成物件

2、方便對檔案與資料夾的屬性資訊進行操作

3、file物件可以作為引數傳遞給流的建構函式

4、了解file類中的常用方法

class  demo

}}

file類的常見方法

1、建立

boolean createnewfile();在指定位置建立檔案,如果該檔案已經存在,則不建立,返回false。和輸出流不一樣,輸出流物件一建立建立檔案,而且檔案已經存在,會覆蓋

boolean mkdir();建立資料夾

boolean mkdirs();建立多個資料夾

2、刪除

boolean delete();刪除,失敗返回fales

void deleteonexit();在程式退出時刪除指定檔案

3、判斷

boolean exists();

isfile();

isdirectory();

ishidden();

isabsolute();

4、獲取

getname();

getpath();

getparent();

getabsolutepath();

lastmodified();

length();

class  demo

public static void method_1()

public static void method_2()

public static void method_3()//建立資料夾

public static void method_4()

public static void method_5()

public static void method_6()//列出機器裡所有碟符 }

public static void sop(object obj)

}

---------------------- asp.net+unity開發、.net培訓、期待與您交流! ---------------------- 

黑馬程式設計師 File類學習總結

file 類,是將檔案或資料夾封裝成物件的類,是檔案或者資料夾物件。new file 物件時引數中是檔案或者資料夾的字串名稱。file 可以作為流物件的引數,同檔名字串作為流物件引數一樣。file類的常用方法總結 1,建立。先new 乙個file 物件,如 file f new file c 123...

黑馬程式設計師 IO流之File類等小結

asp.net unity開發 net培訓 期待與您交流!file物件 專門用於描述系統中檔案或者資料夾的物件。可以用於操作檔案或資料夾的屬性資訊。file物件可以作為引數傳遞給流的建構函式。1 建立。createnewfile 如果此檔案已經存在,則返回false 2 刪除。delete dele...

黑馬程式設計師 Java String 類

asp.net android ios開發 net培訓 期待與您交流!1 string類 1 字串 多個字元組成的一串資料。2 構造方法 a string s new string b string s new string byte bys c string s new string byte b...