Results 1 to 8 of 8
  1. #1
    cecily is offline Member
    Join Date
    Jul 2007
    Posts
    33
    Rep Power
    0

    Default how to find files in given directory

    in my program I have to get directory name&address, in this directory is none, one, or more *.txt(maybe not *.txt files) and I have to read info from all of them.

    on C++ is very easy to do that with "findnext, find last, findfirst", so how can I do this in Java?

  2. #2
    paty is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    You can use java.io.File class and its list() or listFiles() method with FilenameFilter argument. Both return a array of filtered file name or File object in a directory.

  3. #3
    siyuan123 is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default Re: how to find files in given directory

    I think it is a good idea to use TextFinding.com to find files in give directory. It is powerful and easy to use.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to find files in given directory

    Quote Originally Posted by siyuan123 View Post
    I think it is a good idea to use TextFinding.com to find files in give directory. It is powerful and easy to use.
    Does that .com thing run on Unix? Linux? iOS? Android? OS X? Symbian?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: how to find files in given directory

    You ask questions instead of activating 'the machine' ? Perhaps I need to back that up: I refer to the age of this thread.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to find files in given directory

    I was replying to reply #3, which was posted today; and I never activate the machine that says 'beep' for rhetorical question ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,718
    Rep Power
    5

    Default Re: how to find files in given directory

    And I was referring to spam post #3 ;)

    La la la, moving along. Boy it sure is a nice sunny day, isn't it? Too bad this weekend the weather is going to suck.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to find files in given directory

    Quote Originally Posted by gimbal2 View Post
    La la la, moving along. Boy it sure is a nice sunny day, isn't it? Too bad this weekend the weather is going to suck.
    Yep, the weather is cute; I took my precautions already: I filled the fridge with bottles of Grolsch ;-) moved my laptop and all the stuff attached to it to my garden, refilled my supply of tobacco and my old espresso machine is humming peacefully (like a pneumatic hammer) ... it's supposed to stay this way until the evening.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 04:43 AM
  2. Deleting an directory/subdirectory/files
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 07:18 AM
  3. How can I get list of files in a directory
    By karma in forum New To Java
    Replies: 2
    Last Post: 12-14-2007, 11:20 PM
  4. 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
  5. How can i get current directory?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:21 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
  •