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 01:06:38 PDT 2008
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.
<Test3.java>
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.*;
import static java.nio.file.StandardOpenOption.*;
import java.io.File;
public class Test3 {
static SeekableByteChannel sbc = null;
public static void main(String... args) throws Exception {
File file = new File("testfile112");
Path path = file.toPath();
sbc = path.newSeekableByteChannel(CREATE_NEW, DELETE_ON_CLOSE,
WRITE);
ByteBuffer bb = ByteBuffer.wrap("Rajendra".getBytes());
sbc.write(bb);
try {
System.out.println("exists "+file.exists());
path.checkAccess(Access.EXISTS);
path.delete();
} catch (Exception e) {
e.printStackTrace();
}
sbc.close();
}
}
<Test3.java>
<Solaris>
bash-3.00$ $jdk/java Test3
exists false
java.nio.file.NoSuchFileException: testfile112
at
sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at
sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at
sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixPath.checkAccess(UnixPath.java:804)
at Test3.main(Test3.java:18)
</Solaris>
<Windows>
C:\NetBeansProjects\Adhoc\build\classes>d:\b95\bin\java -cp . adhoc.Test3
exists true
</Windows>
Thanks
Rajendra
More information about the nio-dev
mailing list