Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4285834

File.list(FilenameFilter) is not effective for huge directories

XMLWordPrintable

    • x86
    • linux, windows_nt

      Name: krT82822 Date: 10/28/99


      all versions to date

      The File.list() method returns String[]. File.list(FilenameFilter) also returns
      String[]. The problem is that when a directory has tens of thousands of files
      in it, the use of File.list() can cause a huge VM size explosion. In most
      applications processing files, it is not necessary to see all of the files at
      once. One file at a time is fine. The Posix readdir functionality in
      particular is handy in these cases so that one can process all the entries
      in a directory, one at a time.

      I'd like to suggest that a new method be provided in File that will facilitate
      the convienent processing of large directories. Here's my suggestion.

      public void scan( FileEntryAction act ) throws IOException;

      public interface FileEntryAction {
          pubic void processFile( File dir, String name );
      }

      This would allow the activities to be implemented in another class if needed
      and eliminate the need for such a huge array for large directories.

      The reason I am purposing this instead of the alteration of the behavior of
      File.list( FilenameFilter ) to filter as files are found, is that I think the
      above purposal is more general solution and avoids the array creation
      altogether.
      (Review ID: 97165)
      ======================================================================

            alanb Alan Bateman
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: