- import java.io.*;
- import java.util.*;
- import java.lang.*;
- class FilenameFilter1
- {
- public static void main(String[] arg)
- {
- File f2=new File("d://java//day20");
- boolean boo1=f2.exists();
- boolean boo2=f2.isDirectory();
- if (boo1==false|| boo2==false)
- {
- throw new RuntimeException("该文件不存在");
- }
- File[] acc=f2.listFiles(new FilenameFilter()
- {
- public boolean accept(File dir,String name)
- {
- return name.endsWith(".java");//指定列出.java文件
- }
- });
- for (File b:acc )//遍历数组
- {
- sop(b);
- }
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
复制代码 |
|