好久没有写代码了,也好久没有更新我的博客了,昨晚写了这个过滤文件名的程序,遂发之~

这个周末班级要出去秋游了,去浙江,让我失望,兴趣不大,其实我想去黄山.

01 /*name:FileNameFilter
02 *author : Runzhen Wang  
03 *date:2009/11/04
04 */
05 
06 import java.util.*;
07 import java.io.*;
08 import java.lang.*;
09 
10 class FileNameFilter{
11     public void  filter(String strPath,String fname){
12         File f=new File(strPath);
13         String s=new String();
14         if(f.isDirectory()){
15              File[] fList =f.listFiles();
16              for(int i=0;i<fList.length;i++){
17                   if(fList[i].isFile()&&fList[i].getName().endsWith(fname)){
18                        System.out.println(fList[i].getName());
19                   }
20              }
21         }
22 
23     }
24 }
25 
26 public class FileNameFilterDemo{
27     public static void main(String[] args){
28         FileNameFilter fnf=new FileNameFilter();
29         Scanner kb=new Scanner(System.in);
30         String str1=new String();
31         String str2=new String();
32         System.out.print(“输入文件目录:”);
33         str1=kb.next();
34         System.out.print(“输入过滤后缀名:”);
35         str2=kb.next();
36         fnf.filter(str1,str2);
37     }
38 }
Tags: ,. 6,880 views
Home

10 Comments so far

Trackbacks/Pingbacks

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
URLs must be fully qualified (eg: http://blog.nlogn.cn),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.