好久沒有寫程式碼了,也好久沒有更新我的部落格了,昨晚寫了這個過濾檔名的程序,遂發之~
/*name:FileNameFilter *author : Runzhen Wang *date:2009/11/04 */ import java.util.*; import java.io.*; import java.lang.*; class FileNameFilter{ public void filter(String strPath ,String fname){ File f=new File(strPath); String s=new String(); if(f.isDirectory()){ File[] fList =f.listFiles(); for(int i=0;i<fList.length;i++){ if(fList[i].isFile()&&fList[i] .getName().endsWith(fname)){ System.out.println(fList[i].getName()); } } } } } public class FileNameFilterDemo{ public static void main(String[] args){ FileNameFilter fnf=new FileNameFilter(); Scanner kb=new Scanner(System.in); String str1=new String(); String str2=new String(); System. out.print(“輸入檔案目錄:”); str1=kb.next(); System.out.print(“輸入過濾後綴名:”); str2=kb.next(); fnf.filter(str1,str2); } }