sounds like the file is locked for writing. If you don't wait for the proocess to complete then the file would also be locked for reading.
What exactly is the process?
Main Topics
Browse All TopicsHello,
I'm writing a Java app in which the code runs an executable, and I keep running into a catch-22.
The result of running the executable is that it produces a text file.
My catch-22 problem is in using - or not using - the Process.waitFor() method after running the executable.
If I DON'T put in procwaitFor() (line 3), I get an exeption when I try to read in the file in line 4 - 'The process cannot access the file because it is being used by another process.'
If I DO put in proc.waitFor() (line 3), I can read from the file just fine. Only problem is,when I try to delete or overwrite the file later on - I get the same problem - 'The file cannot be deleted because it is being used by another process.'
What I don't completely understand is why waitFor() allows you to read from the file - but then won't let you delete or overwite it later.
Here is the code.
Thanks in advance.
1) Runtime rt = Runtime.getRuntime();
2) Process proc = rt.exec(<executable command that produces a text file>);
3) proc.waitFor(); //If this is included, I can't delete or overwrite the file later. If this is not included, line 4 throws an exception.
4) BufferedReader in = new BufferedReader(new FileReader(<path to file produced>))
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: CPColinPosted on 2009-09-17 at 16:42:09ID: 25362140
Is it possible that your BufferedReader is still around when you try to modify the file? Try calling in.close() before you make any changes.