File類
檔案和目錄(檔案夾)路徑名的抽象表示形式
構造方法
File(String pathname):根據一個路徑得到File物件
File(String parent, String child): 根據一個目錄和一個子檔案/目錄得到File對像
File(File parent, String child): 根據一個父File物件和一個檔案夾/目錄得到File物件
成員方法
public boolean createNewFile(): 創建檔案,如果存在這樣的檔案夾,就不創建了(默認創建檔案在專案路勁下)
public boolean mkdir(): 創建檔案夾 如果存在這樣的檔案夾,就不創建了
public boolean mkdirs(): 創建檔案夾,如果父檔案夾不存在會自動創建,如果存在這樣的檔案夾,就不創建了
public boolean delete(): 洗掉檔案(不走回收站)
public boolean renameTo(File dest): 重命名檔案
public boolean isDirectory(): 判斷是否是目錄
public boolean isFile(): 判斷是否是檔案
public boolean exists(): 判斷是否存在
public boolean canRead(): 判斷是否可讀
public boolean canWrite(): 判斷是否可寫
public boolean isHidden(): 判斷是否隱藏
public String getAbsolutePath(): 獲取絕對路勁
public String getPath(): 獲取相對路徑
public String getName(): 獲取名稱
public long length(): 獲取長度,位元組數
public long lastModified():獲取最后一次的修改時間,毫秒值
public String[] list(): 獲取指定目錄下的所有檔案或者檔案夾的名稱陣列
public File[] listFiles(): 獲取指定目錄下的所有檔案或者檔案夾的File陣列
過濾器:略
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/173108.html
標籤:Java
