Adding Subfiles to a directory fails in WindowsXP
Rajendra Gutupalli
Rajendra.Gutupalli at Sun.COM
Sun Jun 8 23:23:05 PDT 2008
Hi Alan,
Tying to add a subfile to a directory in Windows XP fails with
AccessDeniedException, but I am able to add subfile to a directory using
command line tool "cat".
Please see the following output when tried through command line and
through the program. Please let me the whether the behavior is expected?
Tried in Windows XP with JDK build 91.
output when tried on command line:
<dir report>
06/09/2008 11:31 AM <DIR> zips
</dir report>
Adding subfile txt to the directory zips
C:\>cat > zips:txt
text stream
^Z
Displaying the contents of subfile.
C:\>cat zips:txt
text stream
output when tried through program:
<code>
import java.nio.ByteBuffer;
import java.nio.file.*;
import java.nio.file.attribute.*;
public class NameTest1 {
public static void main(String... args) throws Exception {
Path path = Path.get("C:\\zips");
System.out.println("is Directory " +
Attributes.readBasicFileAttributes(path,false).isDirectory());
NamedAttributeView nav =
path.newFileAttributeView(NamedAttributeView.class, false);
ByteBuffer bb =
ByteBuffer.wrap("Rajendra".getBytes());
nav.write("txt", bb);
}
}
</code>
<result>
is Directory true
Exception in thread "main" java.nio.file.AccessDeniedException: C:\zips
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.WindowsNamedAttributeView.write(WindowsNamedAttributeView.java:271)
at newTests.NameTest1.main(NameTest1.java:23)
</result>
Thanks
Rajendra.
More information about the nio-dev
mailing list