DELETE_ON_CLOSE question

Alan Bateman Alan.Bateman at Sun.COM
Fri Jul 31 08:07:52 PDT 2009


Christian Ullenboom wrote:
> The documentation on DELETE_ON_CLOSE makes its clear that this option
> is just a "best effort attempt to delete the file when closed by the
> appropriate close method". But I expect somehow that the last exists()
> return false and not true in the following example:
>
> Path path = Paths.get( "opa.herbert.tmp" );
> path.deleteIfExists();
> System.out.println( path.exists() );  // false
> path.newOutputStream().close();
> System.out.println( path.exists() );  // true
> path.newOutputStream( StandardOpenOption.DELETE_ON_CLOSE,
> StandardOpenOption.SYNC ).close();
>
> // File should be gone now, or?
>
> System.out.println( path.exists() );  // true
>
> I am using jdk-7-ea-bin-b67-windows-i586-30_jul_2009.
>
> Thanks
>
>  Chris
>   
This doesn't seem right, assuming that there isn't another thread (or 
another program on the system) opening that file at around the same 
time. I just checked this on a couple of systems but didn't duplicate 
it.  As a test, can you put a sleep in before you check if the file 
exists? Also, which Windows is this and does your virus checker have 
real-time protection turn on? (we've seen a few cases with virus 
checkers probing newly created files, I can't of course say if this if 
this is anything to do it).

-Alan.



More information about the nio-discuss mailing list