Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: Get directory files list as a stream

  1. #1
    Dijkstra is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Get directory files list as a stream

    Hi
    Probably at first glance the question seems very simple but it's no so.
    The system I'm writing kinda content analytic tool which knows to work with File System as
    one of possible content source repository.We need to run through provided File System root folder and process all files under the root.The system is required to be very responsive, the problems starts when the root folder is located on the remote machine and the number of files under each folder is extremely big (talking about millions of files under single folder)

    The way I use to get all available files from folder is very straightforward

    File.listFiles()

    I'm afraid it's the only way java api provides to obtain the list of all files (names/file objects)

    As you know the method returns list of file when it completed to read all of them.
    My goal is to find a way to get this list kinda steam

    Any thoughts, suggestions will be appreciated

  2. #2
    rfq
    rfq is offline Member
    Join Date
    Mar 2012
    Location
    Novosibirsk, Russia
    Posts
    15
    Rep Power
    0

    Default Re: Get directory files list as a stream

    I did not check that, but probably File.listFiles(FileFilter filter) can help. Run it in in a separate thread. Make FileFilter.accept(File path) to write path into a blocking queue and return false. In another thread, read paths from the queue.

  3. #3
    rfq
    rfq is offline Member
    Join Date
    Mar 2012
    Location
    Novosibirsk, Russia
    Posts
    15
    Rep Power
    0

    Default Re: Get directory files list as a stream

    File.listFiles() won't work as it calls File.list() internally.
    But java 7 has new class Files with methods newDirectoryStream() and walkFileTree().

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Get directory files list as a stream

    Further proof that I really need to start doing more stuff in Java 7.
    Norm likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Dijkstra is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Get directory files list as a stream

    Quote Originally Posted by rfq View Post
    File.listFiles() won't work as it calls File.list() internally.
    But java 7 has new class Files with methods newDirectoryStream() and walkFileTree().
    thanks, java 7 seems exactly what i'm looking for,good point

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2011, 03:28 PM
  2. Create a table with buttons and the files list of a directory.
    By danielpereira in forum Advanced Java
    Replies: 1
    Last Post: 11-22-2010, 06:43 PM
  3. Populating a gui list box with the files in a directory
    By josejvelezcolon in forum New To Java
    Replies: 1
    Last Post: 08-10-2009, 04:50 PM
  4. how to list certain files in a given directory in java
    By corpusluteum in forum New To Java
    Replies: 6
    Last Post: 09-24-2008, 12:19 AM
  5. 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

Posting Permissions

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