一、File類的概念
An abstract representation of file and directory pathnames(它是文件和目錄路徑名的一個(gè)抽象的表現(xiàn)形式)
二、 File類的成員變量
? ??成員變量均為靜態(tài)常量,且能夠適配不同的操作系統(tǒng)
1? ? staticString?pathSeparator
? ? ? ? ? ?它表示與系統(tǒng)有關(guān)的路徑分隔符,為了方便,它被表示為一個(gè)字符串。?
2? ? ?staticchar?pathSeparatorChar
? ? ? ? ? ? 它表示與系統(tǒng)有關(guān)的路徑分隔符。?
3? ? ?static?String?separator
? ? ? ? ? ? ?它表示與系統(tǒng)有關(guān)的默認(rèn)名稱分隔符,為了方便,它被表示為一個(gè)字符串。?
4? ? ?staticchar?separatorChar
? ? ? ? ? ? ?與系統(tǒng)有關(guān)的默認(rèn)名稱分隔符。? ? ? ??
三、File類的構(gòu)造方法
????public?File(String?pathname)?????通過將給定的路徑名字符串轉(zhuǎn)換為抽象路徑名來創(chuàng)建新的File實(shí)例。
????public?File(String?parent,String?child)? ? ? ? ? ? ? 從父抽象路徑名和子路徑名字符串創(chuàng)建新的File實(shí)例。
????public?File(File?parent,String?child)? ? ? ? ? ? ? 從父路徑名字符串和子路徑名字符串創(chuàng)建新的File實(shí)例。
四、常用方法
? ?public boolean createNewFile()? 若文件不存在則創(chuàng)建新文件
? ?public boolean mkdir()? ? ? ? ? ? ? ? 創(chuàng)建目錄 make Directory
? ?public boolean mkdirs()? ? ? ? ? ? ? 創(chuàng)建目錄及不存在的父目錄
? ?public boolean delete() 刪除文件及空目錄
? ?public boolean renameTo(File dest)?
? ? a.? 如果源文件和目標(biāo)前父目錄一致,就是更名
? ? b.? 如果源文件和目標(biāo)前父目錄不一致,就是剪切再更名
? ?public String[] list() ????????????????返回file下的文件和目錄名稱(字符串)
? ?public File[] listFiles()? ????????????返回file下的文件和目錄(文件)
? ?public String[] list(FilenameFilter filter)? ????????根據(jù)filter過濾返回file下文件和目錄名稱
? ?public? File[] listFiles(FileFilter filter)? ????????根據(jù)filter過濾返回file下文件和目錄
? ?public?boolean?isFile()? ? ? ? ? ? ? ? ?是否是文件
? ?public?boolean?isDirectory()? ? ? ? 是否是目錄
? ?public?boolean?canRead()? ? ? ? ? ?是否可讀
? ?public?boolean?canWrite()? ? ? ? ? ?是否可寫
? ?public?boolean?exists()? ? ? ? ? ? ? ? 是否存在
? ?public?boolean?isHidden()? ? ? ? ? ?是否隱藏
? ?public?long?length()? ? ? ? ? ? ? ? ? ? ? 長度
? ?publicStringgetAbsolutePath()? ? ?絕對(duì)路徑
? ?public?String?getPath()? ? ? ? ? ? ? ? ?定義的路徑
? ?public?String?getName()? ? ? ? ? ? ? ?獲取file名字
? ?public?long?lastModified()? ? ? ? ? ? ?最后一次修改時(shí)間