Java file filtering code sharing (filter by drop out)

  • 2020-04-01 03:26:09
  • OfStack

Haven't written code for a long time, also haven't updated my blog for a long time, last night wrote this filter file name program, then send 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( "Enter the file directory : " );
     str1=kb.next();
     System.out.print( "Enter the filter suffix name : " );
     str2=kb.next();
     fnf.filter(str1,str2);
   }
 }



Related articles: