You use PosixFilePermission
which can be used only with operating systems which are compatibile with POSIX:
A file attribute view that provides a view of the file attributes commonly associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards.
Operating systems that implement the POSIX family of standards commonly use file systems that have a file owner, group-owner, and related access permissions. This file attribute view provides read and write access to these attributes`
Windows unfortunatelly doesn't support POSIX file systems so this is why your code doesn't work. In order to create a directory in Windows you should use:
new File("/path/to/folder").mkdir();
The /
will be automatically changed to \
in Windows. If you want to create the whole path at once you have to use mkdirs()
method. More info: http://docs.oracle.com/javase/6/docs/api/java/io/File.html
In order to set file permissions in Windows you have to use setReadable()
, setWritable()
and setExecutable()
. That are File
class methods and set only file owner's permissions. Note that mentioned methods were added in Java 1.6. In older versions you would have to use (Windows version):
Runtime.getRuntime().exec("attrib -r myFile");