Android File類 根據官方文件理解

2021-09-07 21:58:33 字數 2505 閱讀 8310

file有四個建構函式

public file(file dir,string name)

引數為file和string,file制定構造的新的file物件的路徑,而string制定新的file名字

public file(string path)

引數為string,構造乙個新的file使用制定的路徑

public file(string dirpath,string name)

dirpath為指定的檔案路徑,name為檔案的名字

public file(uri uri)

構造新的檔案使用uri指定路徑

file getfilesdir()

返回路徑中的目錄,並且保持應用程式檔案。在這裡獲取到的是/data/data//files目錄,返回乙個file

file  getcachedir()

方法用於獲取/data/data//cache目錄

boolean delete()

刪除檔案

public boolean 

equals

(object obj)

判斷obj和呼叫的物件是否相同

public file getabsolutefile()

返回乙個新的檔案,該檔案的絕對路徑是呼叫的file的路徑

public string getabsolutefile()

返回該檔案的絕對路徑

public long getfreespace()

返回在分割槽上剩餘的位元組數量,包括當前file的路徑

public string getname()

返回檔案的名稱

public string getpath()

返回檔案的路徑

public long gettotalspace()

返回分割槽的總位元組大小

public long getusablespace()

返回分割槽可用位元組的大小

public boolean isdirectory()

判斷是否為資料夾

public boolean isfile()

判斷是否為檔案

public boolean ishidden()

判斷是否為作業系統定義的隱藏檔案

public long lastmodified()

返回最後一次修改該檔案的時間,以毫秒計算,從2023年1月1日開始算

public long length()

返回檔案的長度,單位為位元組

public boolean mkdir()

建立乙個資料夾,當父目錄存在才能成功建立

public boolean mkdirs()

建立乙個資料夾,可可附帶建立父目錄

public boolean renameto(file newpath)

重新命名newpat**件夾

public boolean setwritable(boolean writable,boolean owneronly)

writable 如果為真,對該檔案有寫許可權,否則沒有

owneronly 如果為真,只對檔案的擁有者有寫許可權,否則,對其他人也有寫許可權。

public boolean setwritable(boolean writable,true)

同setwritable(writable,true)乙個意思

public boolean setreadonly()

對檔案只有讀許可權

public boolean setreadable(boolean readable,boolean owneronly)

readable 如果為真,對該檔案有讀許可權

owneronly 如果為真,只對檔案的擁有者有讀許可權,否則,對其他人也有讀許可權

public boolean setreadable(boolean readable)

同setreadable(boolean readable,true)乙個意思

public string tostring()

tostring是乙個object類的方法,可以返回乙個物件的字串表示。

public uri touri()

返回乙個檔案的uri

Android File類 根據官方文件理解

file有四個建構函式 public file file dir,string name 引數為file和string,file制定構造的新的file物件的路徑,而string制定新的file名字 public file string path 引數為string,構造乙個新的file使用制定的路徑...

Android File類 根據官方文件理解

file有四個建構函式 public file file dir,string name 引數為file和string,file制定構造的新的file物件的路徑,而string制定新的file名字 public file string path 引數為string,構造乙個新的file使用制定的路徑...

布局類 04 類 QBoxLayout 官翻

公共函式 重寫的公共函式 總結qboxlayout類將子視窗小部件水平或垂直排列。qboxlayout獲取空間 從其父布局或parentwidget 將其劃分為一行框,並使每個託管小部件填充乙個框。如果qboxlayout的方向是qt horizontal,則框將以適當的大小放置在一行中。每個小部件...