安卓File類彙總

2021-06-26 12:47:35 字數 3112 閱讀 1667

file類

建構函式

引數

f

ile(file dir,string name)

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

file(string path)

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

file(uri uri)

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

file(string dirpath,string name)

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

功能函式

功能

ge

tfilesdir()

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

getcachedir()

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

boolean delete()

刪除檔案

public boolean 

equals

(object obj)

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

public file getabsolutefile()

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

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)

重新命名newpath資料夾

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

安卓學習問題彙總

1.textview.settext string text text必須為string,如果傳入int,不會報編譯錯誤,但是會報執行時異常。2.獲取乙個view的幾種方法 a 傳入int context.findviewbyid int b 傳入string 通過反射獲取 c 給view設定tag...

安卓LOG封裝類

我們在安卓開發過程中經常需要測資料,安卓系統自帶的log非常方便,但寫起來有點複雜,我將它封裝如下 public class logs public static void d string msg public static void e string msg public static void...

安卓工具類 FileUtils

public class minefileutils file file new file filepath intent.addflags intent.flag activity new task 設定標記 intent.addflags intent.flag grant read uri p...