A couple of solutions come to mind:
1. Temporarily rename the file when one thread accesses it and then rename it back to its original name when the thread is done
2. Store the file in a variable if it's not too large and then delete the actual file. When done recreate the file and put the contents back
File f = new File("smallFile.txt");
SomeReader sr = new SomeReader(f);
String fileContents = sr.getContents();
sr.close();
f.delete();
//do other stuff with file
f.createNewFile();
or
File f = new File("smallFile.txt");
f.renameTo("tempName");
//do other stuff with file
f.renameTo("smallFile.txt");
This is a hack way of doing it but, if another Thread tries to access the file it won't be there.
Using "synchronized" methods works best.
Message was edited by:
billyChill