1. 程式人生 > >簡單的遞迴刪除xx路徑的檔案

簡單的遞迴刪除xx路徑的檔案

//	刪除txt檔案
	//File file=new File("J:\\作業包");//路徑
//	public static void delFile(File file){
//		if(file.isFile()){//如果該項屬於檔案,那麼進行判斷如果是txt刪除、
//			String strr=file.getName();
//			String str=strr.substring(strr.lastIndexOf(".")+1);
//			if("txt".equals(str)){
//				file.delete();
//			}
//		}
//		else{
//			File []f=file.listFiles();
//			for (File file2 : f) {
//				delFile(file2);//如果是資料夾,則去資料夾裡面刪除對應的項
//			}
//		}
//	}

      遞迴的列子其實舉出一個弄懂了就很形象的可以舉一反三。