package com.dazhi;
import java.io.File;
public class test {
public static void main(String[] args) {
File f=new File("F://课堂例子//firstweek//zip");
MyFilter my=new MyFilter();
my.setSuffix("class");
String []s=f.list(my);
System.out.println(s.length);
for(String name:s){
System.out.println(name);
}
}
}
过滤器:MyFilter.java
package com.dazhi;
import java.io.File;
import java.io.FilenameFilter;
public class MyFilter implements FilenameFilter{
private String suffix;
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(suffix);
}
}
import java.io.File;
public class test {
public static void main(String[] args) {
File f=new File("F://课堂例子//firstweek//zip");
MyFilter my=new MyFilter();
my.setSuffix("class");
String []s=f.list(my);
System.out.println(s.length);
for(String name:s){
System.out.println(name);
}
}
}
过滤器:MyFilter.java
package com.dazhi;
import java.io.File;
import java.io.FilenameFilter;
public class MyFilter implements FilenameFilter{
private String suffix;
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(suffix);
}
}