listing the files under a directory using Java API

Discussions

General J2EE: listing the files under a directory using Java API

  1. listing the files under a directory using Java API (2 messages)

    I have a millions of files under a directory. I don't want get all the files from that directory using the following code snippet File file = new File("C:
    files"); String[] files = file.list() or File[] files = file.listFiles(); which would kill my server. Is there a way such that i can get first 25000 files from directory and process them and get the next 25000 and process them and so on... I tried but didn't find help on this one Any help is greatly appreciated
  2. One way I found was to look beyond java for it, using the OS shell commands -- detecting if its windows or unix and running dir or ls with its various options Run the command as a thread and get access to the process's stdout / stderr and process the stream. It is usually quicker than JAVA API's access to the filesystem. It's a bit more complicated than the simple java api, but the performance improvement is worth it.
  3. Please,

     

    Could you write a code example for this problwem?