请问,调用那个函数去增加文件过滤是,下面的选择项阿
例如
    jsp
    java
    html
    xml
这种格式的
谢谢回答

解决方案 »

  1.   

    继承filefilter,定义accept(File file)方法
    例子:
    class CertFilter extends javax.swing.filechooser.FileFilter {
    final static String cfg = "cer"; public boolean accept(File f) {
    String s = f.getName();
    int i = s.lastIndexOf('.');
    if (i > 0 && i < s.length() - 1) {
    String extension = s.substring(i + 1).toLowerCase();
    if (cfg.equals(extension)) {
    return true;
    } else {
    return false;
    }
    }
    ;
    return false;
    } // The description of this filter
    public String getDescription() {
    return "certificate files (*.cer)";
    }
    }
      

  2.   

    过滤d:\\java下的.java文件:
    import java.io.*;class Filter implements FilenameFilter{
    String extent;
    public Filter(String extent){
    this.extent=extent;
    }

    public boolean accept(File dir,String name){
    return name.endsWith("."+extent);
    }

    }public class ListFileApp{
    public static void main(String args[]){
    File dir = new File("d:\\java");
    Filter filter = new Filter("java");
    System.out.println("start list .java files...");
    String files[]=dir.list(filter);
    for(int i=0;i<files.length;i++){
    File f = new File(dir,files[i]);
    if(f.isFile())
    System.out.println("file:"+f);
    else
    System.out.println("sub dir:"+f);
    }
      }
    }
      

  3.   

    多谢,这些我知道了,我想问的是,实现多个过滤 比如,一种选择是java 另一种选择是
    xsl 等等这样的,上面的两个程序只是实现了一种过滤方法