I haven’t written code for a long time, and I haven’t updated my blog for a long time. I wrote this program to filter file names last night, and then I posted it~
/*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("Input file directory:"); str1 =kb.next(); System.out.print("Enter filter suffix name:"); str2=kb.next(); fnf.filter(str1,str2); } }