• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Listing Directory contents

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way I can iterate through the contents of a directory without having to use listFiles ?

I am trying to avoid having to store the file names in memory, if there is going to be just way too many files...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not using current standard Java libraries. Check out RFE 4285834. Too bad. I think your best bet at this point is, if you can afford to give up cross-platform compatibility (or if you can put in extra work to make it work on other platforms on a case-by-case basis), use Runtime.getRuntime().exec() to exec a simple script to list the files in a directory and put those names in a text file. (In Unix this could be as simple as "ls -1 [directory_path] > [output_file_name]". Then you can read the file one line at a time and do whatever you want with each file name. Or, you could use JNI instead. Hope that helps...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic