IO流 前置內容 File

2021-09-01 22:59:52 字數 918 閱讀 9097

例如: file f-new file("e:\\demo\\a.txt"); 或者e:/demo/a.txt

""裡面的有可能是目錄名,也有可能是檔名.    注意a.txt寫了不一定代表存在這個檔案,只是描述了一句話而已.

建立: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 get absolutepath()//獲取絕對路徑

public string getpath()//獲取相對路徑

public string getname()//檔名

public long length()//獲取檔案大小. 單位mb

public long lastmodified()//最後修改毫秒值

public strnig list()//獲取指定目錄下的資訊列表字串形式

public file listfiles()獲取指定目錄下的資訊列表

IO基礎內容 File

上面兩種操作成為io操作 file類的主要函式 檔案過濾 查詢包含指定檔名的檔案 遞迴遍歷目錄的方法 public class filedemo 定義方法,實現目錄的全遍歷 public static void getalldir file dir else 檔案過濾器 過濾乙個目錄下的指定副檔名的...

判斷file空 IO流(二) File類

file類的建構函式 通過將給定路徑名字串轉換為抽象路徑名來建立乙個新 file 例項。引數 string pathname 字串的路徑名稱 路徑可以是以檔案結尾,也可以是以資料夾結尾 路徑可以是相對路徑,也可以是絕對路徑 路徑可以是存在,也可以是不存在 建立file物件,只是把字串路徑封裝為fil...

IO流輸入輸出 File

file類是io包中唯一代表磁碟檔案本身的物件。通過file來建立,刪除,重新命名檔案。常用方法 file file1 new file src a.txt 指定當前workspace src下的a.txt檔案 file file2 new file c users l xd desktop tem...