Existence of a file fails if it is created with SBC(C_N, W, D_ON_C) (Sol)

Rajendra Gutupalli Rajendra.Gutupalli at Sun.COM
Thu Sep 25 02:52:23 PDT 2008


Alan Bateman wrote:
> Rajendra Gutupalli wrote:
>> Hi Alan,
>>
>> When a SekableByteChannel is opened with option DELETE_ON_CLOSE, any 
>> further attempt to check the existence of the file (and also deletion 
>> of the file) fails in Solaris.
>> In Windows it is not a problem. Please see the following code and 
>> result in Solaris and Windows.
> Yes, the difference is observable but the spec is clear that the 
> details as to when and how the file is deleted are implementation 
> specific (and therefore unspecified). The intended use-case is a work 
> file that you want removed automatically when the channel/stream is 
> closed or the VM terminates. Ideally, the file should not be visible 
> in the file system on Windows after it is opened with this option but 
> it has always been the case that files pending delete are visible 
> until the last handle is closed.
>
Thanks Alan,

I have one more query. Is it okay to create a file to which 
SekableByteChannel is opened for DELETE_ON_CLOSE. ie. In the following 
code snippet Should path.createFile() succeed or should it throw 
FileAlreadyExistsException?

Path path = Paths.get("testfile"); //testfile does not exists
SeekableByteChannel sbc = 
path.newSeekableByteChannel(CREATE_NEW,WRITE,DELETE_ON_CLOSE);
path.createFile();
sbc.close();

As of now in Solaris path.createFile() creates the file "testfile"and 
after the execution of code the file "testfile" continues to exist. But 
in Windows it throws FAEE.

Thanks
Rajendra.




More information about the nio-dev mailing list