Reputation: 1837
i am running a java program on a redhat linux machine. The program works just fine on my windows laptop but, when i run on the linux server i get a message saying: "Too many open files". Here is the code (roughly - i took out some parts) i'm working with:
for(String f : fileList) {
File file = new File(f);
PdfReader reader = new PdfReader(f);
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
if(condition is true){
String s = FilenameUtils.getFullPath(f);
File renameFile = new File(s + newfilename );
FileUtils.moveFile(file, renameFile);
break;
}
}
}
The fileList is typically anywhere from 10,000 to 100,000 elements in length. I know that i should probably close the PdfReader
object - and i will. But, i was wondering if the regular Java File
objects can also cause the "Too many open files" error and if so, how do i properly "close" those kinds of objects?
Upvotes: 0
Views: 591
Reputation: 77234
No. The Java File
object basically wraps a filename, but it doesn't hold an open file handle until you use it to open a stream or reader.
Upvotes: 2
Reputation: 7870
Call close() on your handlers to release resources:
reader.close();
Upvotes: 2