Gusenbauer Stefan wrote:
I'm writing a little application and therefore I've implemented unit tests. There i've a method to test my removeindex method, the problem is can't delete the cfs file. When i try to delete it manually it works. But within the tests the method cannot delete this file. I've searched through my code but IndexWriter is always closed. I've read in another java forum that it is possible that are streams on this file open. Is it possible to tell lucene or better to force lucene, that it should close all streams. segments and deleteable i can delete without any problems. I've also tried to force unlock but this makes no changes to the result.sorry just a few google searches later i found a fine workaround for me
thanks
stefan
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
the original is found at http://forum.java.sun.com/thread.jspa?threadID=158689&messageID=2033384 by Mike 0'Connor. I've made it static and singleton and added a boolean return value which is true if the file is really deleted. But it would be nice if any of you know why there are open streams or handles on the cfs file? Maybe it is a lucene bug?
thanks
Stefan
public class FileDeleter {
private FileDeleter() {};
public static boolean deleteFile(File file) {
deleteFile(file,10,0);
if(!file.exists()) {
return true;
}//ifs
else {
return false;
}//else
}
private static void deleteFile(File file, int tries, int tried) {
if (!file.delete()) {
System.gc(); // In case the JVM itself thinks it has a file handle
if (!file.delete()) {
try { // Now wait and see if it goes away
Thread.sleep(200);
}//try
catch (InterruptedException e) {}
// Potential perma-loop avoided with counter
// if still there after specified tries, give
// up, you've got another problem
if( tried < tries ){
deleteFile(file,tries,tried++);
}//if
}//if
}//if
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]