access error with FileChannel.open(dir) on windows

Akhil Arora akhil.arora at oracle.com
Fri Feb 22 19:07:10 UTC 2013


The following simple program throws access denied on windows7 for any 
directory path passed as the first arg. Works fine on linux, and works 
fine for args that are file. Verified that the exception occurs on a 
coworker's windows7 as well. Is this a bug or am I doing something 
wrong? Thanks

$java open .

Exception in thread "main" java.nio.file.AccessDeniedException: .
         at 
sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
         at 
sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
         at 
sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
         at 
sun.nio.fs.WindowsFileSystemProvider.newFileChannel(WindowsFileSystemProvider.java:114)
         at java.nio.channels.FileChannel.open(FileChannel.java:287)
         at open.main(open.java:12)

import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.nio.file.OpenOption;
import java.util.EnumSet;
import java.util.Set;

public class open {
     public static void main(String[] args) throws IOException {
         Set<? extends OpenOption> options = 
EnumSet.noneOf(StandardOpenOption.class);
         FileChannel fc = FileChannel.open(Paths.get(args[0]), options);
     }
}


More information about the nio-dev mailing list