• Post Reply Bookmark Topic Watch Topic
  • New Topic

File.exists() returns true

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have a thread that checks in a folder if 2 files exist....

When the files are copied the exists() method returns true even if the files is removed??

When i move the server to another machine it works fine? Somebody how can help!

mac os x operating system on both machines
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes it takes a little while before the file system cache catches up with operations. So if you call exists() right after delete(), it might return true. If you let the thread sleep for, say, 100ms, it should return false.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

But it takes a minute before it returns false? What can be wrong?

I check in a while loop

while( true ){
File f = new File( Path , myFile );
if( ! f.exists() ){
break;
}else{
try{
Thread.sleep( 100 );
}catch( InterruptedException e ){
}
}

}
 
Dave T Taylor
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a thought, but why not try reading the file rather than just testing if it exists? If the file has been deleted then you shouldn't be able to read it.

You could then trap this inside a try/catch statement and continue execution of your code, knowing the file does not exist.


Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!