java - Too many files open
Hi, i am creating program that gets 'key' string and directory path and finds if key string is present in any file under given path,
everything seemed OK but when i put path like "/" after 5 mins i get error : Too many opened files. I've minimalized opened File object at the same time as much as posible, tried to call System.gc(),tried to close every stream every opened file, google but i still cannot search in bigger directories. Algorithm (mine one is much bigger so i tried to make it as small as possible: read 'path'; read 'key'(set as public); #& call method get('path') { #& String[] files = all files in 'path' directory; for(String s : files) { if File('path' + s).isDirectory() call again method get: get(path + "/" + s); //Searching in subdirectories if File('path' + s).isFile() open it and search if 'key' is there -if yes write file; #& } } #& - where i tried System.gc() Anyone has some idea why I always get that runtime error ? (I need it to search hundreds of GB so when my 40GB partition do this what will bigger one do :( ) |
Quote:
|
You mean I/O streams ? Yea, I always close them all.
OOh - does that error mean that i have unclosed I/O Streams or too many File objects ? |
Quote:
|
Yea, I always invoke 'stream'.close();
|
Quote:
|
And when i have opened instance of java.io.File class does it counts as opened file or it has nothing to do with that?
|
Quote:
man 3 fopen (or http://linux.die.net/man/3/fopen ) counts. You need to understand how Java stuff translates into OS stuff - I am not a Java guy. |
All times are GMT -5. The time now is 09:39 AM. |