1 建立檔案或者檔案夾:有異常
1.1、建立文本檔案
1.2、建立檔案夾
1.3、建立多級檔案夾
提示:如果檔案夾已經存在則不重新建立
2 删除檔案
3 查詢檔案
3.1、判斷某個路徑的檔案是否存在
3.2、擷取檔案的大小
String字元串:length(),傳回字元串中字元的個數
數組: 數組名.length 是屬性,擷取數組中元素的個數
集合 集合對象.size()傳回集合中元素的個數
3、擷取檔案的名稱
4、擷取檔案的路徑
4 遞歸
package com.zheng.io;
import java.io.File;
public class FileDemo4 {
public static void showFile(String pathname){
File f1=new File(pathname);
//判斷檔案是否是檔案夾
boolean flag1=f1.isDirectory();
if(flag1){//是檔案夾
File [] files=f1.listFiles();//得到檔案夾下的所有檔案
for (int i=0;files!=null&&i<files.length;i++) {
//判斷是否是檔案夾
boolean flag2=files[i].isDirectory();
if(flag2){
showFile(files[i].getPath());
}else{
//擷取檔案的路徑
String filepath=f1.getPath();
System.out.println("普通檔案:====="+filepath);
}
}
}else{//不是檔案夾
String filePath=f1.getPath();
System.out.println("普通檔案=======:"+filePath);
}
}
public static void main(String[] args) {
FileDemo4.showFile("D:\\");
}
}