Saturday, January 20, 2018

Get The html file list using the FileFilter In java



 The following java program get the list of all html file from the directory folder



import java.io.File;
import java.io.FileFilter;


class GetHtmlFilesList {
    FileFilter htmFileFilter = new FileFilter() {
        @Override
        public boolean accept(File file) {
            if (file.getName().endsWith(".htm")) return true;
            else return false;
        }
    };
    public File[] getListOfHtmFiles(String dataPath) {
        File dataFolder = new File(dataPath);
        return dataFolder.listFiles(htmFileFilter);
    }
  public static void main(String arg[]) {
        String DATA_PATH="/home/brij/mathmuni2/docs/2017-11-30_updated/htm_and_images";
        GetHtmlFilesList getHtmlFileList=new GetHtmlFilesList();
        File[] fileList=getHtmlFileList.getListOfHtmFiles(DATA_PATH);
       
        for (File f : fileList) {
            System.out.println("File Name = "+f.getName());
        }
  }
}

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...