rnicholus
asked on
java.io.Exception: Too many open file when running 'ls -lrt' in Java program
This is related to my post here: https://www.experts-exchange.com/questions/24127839/How-to-find-the-latest-file-using-Linux-command-in-Java-program.html
Where I want to get the latest file using Linux command in my Java program.
The problem is after running it for about one day, it starts throwing "IOException: Too many open files".
How should I handle this?
I have closed resources after I used it.
Where I want to get the latest file using Linux command in my Java program.
The problem is after running it for about one day, it starts throwing "IOException: Too many open files".
How should I handle this?
I have closed resources after I used it.
Process process = Runtime.getRuntim().exec(new String[] { "bash", "-c", "ls -lrt /directory1/subdirectory | tail -1" });
......
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
....
....
// Close resources.
try { if ( stdInput != null ) { stdInput.close(); stdInput = null; } } catch (Exception ex) {}
try { if ( stdError != null ) { stdError.close(); stdError = null; } } catch (Exception ex) {}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The OS will allow you a certain number of file handles, after which it'll start complaining
ASKER
I've been running the program for a while now after adding call to destroy() method. It seems to solve the problem.
Thanks. ! :)
Thanks. ! :)
Good :-)
ASKER
Why need to wait for a while before getting that exception.