Showing posts with label File Handling. Show all posts
Showing posts with label File Handling. Show all posts

Saturday, 28 July 2012

Directory of .HTML Files


    // Directory of .HTML Files
        import java.io.*;
        class DirListOnly {
        public static void main(String args[]) {
                String dirname="/subha/html";
                File f1=new File(dirname);
                FilenameFilter only=new OnlyExt("html");
                String s[]=f1.list(only);
                for(int i=0;i<s.length;i++) {
                        System.out.println(s[i]);
                }
             }
        }

FilenameFilter example in java


import java.io.*;
class OnlyExt implements FilenameFilter {
        String ext;
        public OnlyExt(String ext)
       {
        this.ext="."+ ext;
        }
        public boolean accept(File dir,String name)
        {
        return name.endsWith(ext);
        }
}