Results 1 to 3 of 3
  1. #1
    KevMeistr is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default Filename Filter problem

    Hi there..

    I recently discovered the File class and how useful it is when searching for files in a certain directory..

    Now, I want to pass 2 string parameters;

    1. Directory name
    2. A filter

    The passing of the 2 strings will be in a constructor..

    Is there any way that I'm able to search in a directory for a filter corresponding to the string "E.*\.htm"..the reason for doing this is so that I can put .htm files starting with "E" into an array by themselves

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    2. A filter
    You may design a class that extends FileFilter....

    And override the two methods getDescription() and accept()

    All filtering operations should be done on overriden accept(File) method....

    You may browse the FileFilter class in src file(zip) that can be found inside jdk folder....(just in case you are curious about its implementation)

    Hope that helps,
    sukatoa
    Last edited by sukatoa; 06-12-2008 at 03:31 PM.
    freedom exists in the world of ideas

  3. #3
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Try this

    Java Code:
    File dir = new File("E:\");
    File[] files = dir.listFiles(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    return name.startsWith("*.htm") ? true : false;
                }
            });
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

Similar Threads

  1. Replies: 5
    Last Post: 06-06-2008, 09:31 AM
  2. web content filter or internet filter
    By sundarjothi in forum Advanced Java
    Replies: 3
    Last Post: 05-15-2008, 11:36 AM
  3. Reading a directory and getting the filename
    By mrjunsy in forum Advanced Java
    Replies: 1
    Last Post: 05-10-2008, 02:36 AM
  4. servlet Filter problem
    By saint_jorjo in forum New To Java
    Replies: 1
    Last Post: 03-13-2008, 12:05 PM
  5. Need a filter
    By revathi17 in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •