Results 1 to 3 of 3
  1. #1
    karma is offline Member
    Join Date
    May 2007
    Rep Power

    Question How can I get list of files in a directory

    I want get the list of filenames, such as "d:\javafile\*.java"
    The return values could be String[] or FIle[].

    How can i do this?

  2. #2
    FaRuK is offline Member
    Join Date
    May 2007
    Rep Power


    Hi Karma,

    I think you'd do it something like:

    Java Code:
      File dir = new File ("d:/javafile/");
      String [] javafiles = dir.list(filter);
        for (int i = 0; i < strs.length; i++) {
          System.err.println (strs[i]);
    And for filtering only *.java files, you can use the following filter:

    Java Code:
    FilenameFilter filter = new FilenameFilter() {
      public boolean accept(File dir, String name) {
        return name.endsWith(".java");

  3. #3
    MattStone is offline Member
    Join Date
    Dec 2007
    Rep Power


    above should work....
    depending on what you want.....

    You may want to follow along with me, LoL
    getting kinda crazy. LoL. but similar post.

Similar Threads

  1. how to find files in given directory
    By cecily in forum New To Java
    Replies: 7
    Last Post: 07-04-2014, 12:03 PM
  2. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM
  3. Deleting an directory/subdirectory/files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 07:18 AM
  4. Replies: 20
    Last Post: 12-17-2007, 03:20 PM
  5. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:14 AM

Posting Permissions

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