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
-
listing the files under a directory using Java API (2 messages)
- Posted by: kumar dave
- Posted on: January 26 2007 13:50 EST
Threaded Messages (2)
- Re: listing the files under a directory using Java API by Ankur Kapadia on October 03 2007 21:01 EDT
- Re: listing the files under a directory using Java API by edmondo sena on September 13 2011 11:32 EDT
-
Re: listing the files under a directory using Java API[ Go to top ]
- Posted by: Ankur Kapadia
- Posted on: October 03 2007 21:01 EDT
- in response to kumar dave
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. -
Re: listing the files under a directory using Java API[ Go to top ]
- Posted by: edmondo sena
- Posted on: September 13 2011 11:32 EDT
- in response to Ankur Kapadia
Please,
Could you write a code example for this problwem?