Tuesday, 15 April 2014

nio - java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute on Windows -



nio - java.lang.UnsupportedOperationException: 'posix:permissions' not supported as initial attribute on Windows -

i using java7 file api write class workig fine on ubuntu creating directories when run same code in windows throwing error

exception in thread "main" java.lang.unsupportedoperationexception: 'posix:permissions' not supported initial attribute @ sun.nio.fs.windowssecuritydescriptor.fromattribute(unknown source) @ sun.nio.fs.windowsfilesystemprovider.createdirectory(unknown source) @ java.nio.file.files.createdirectory(unknown source) @ java.nio.file.files.createandcheckisdirectory(unknown source) @ java.nio.file.files.createdirectories(unknown source) @ com.cloudspoke.folder_permission.folder.createfolder(folder.java:27) @ com.cloudspoke.folder_permission.main.main(main.java:139)

my folder class code is

package com.cloudspoke.folder_permission; import java.io.ioexception; import java.nio.file.files; import java.nio.file.path; import java.nio.file.attribute.fileattribute; import java.nio.file.attribute.posixfilepermission; import java.nio.file.attribute.userprincipal; import java.util.set; public class folder{ //attributes required creating folder private userprincipal owner; private path folder_name; private fileattribute<set<posixfilepermission>> attr; public folder(userprincipal owner,path folder_name,fileattribute<set<posixfilepermission>> attr){ this.owner=owner; this.folder_name=folder_name; this.attr=attr; } //invoking method create folders public void createfolder(){ seek { //createdirectories function used overwriting existing folder instead of createdirectory() method files.createdirectories(folder_name, attr); files.setowner(folder_name, owner); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } system.out.println("created folder "+this.folder_name); } }

error coming createfolder method of folder can 1 please tell how remove error??

you utilize posixfilepermission can used operating systems compatibile posix:

a file attribute view provides view of file attributes commonly associated files on file systems used operating systems implement portable operating scheme interface (posix) family of standards.

operating systems implement posix family of standards commonly utilize file systems have file owner, group-owner, , related access permissions. file attribute view provides read , write access these attributes

windows unfortunatelly doesn't back upwards posix file systems why code doesn't work. in order create directory in windows should use:

new file("/path/to/folder").mkdir();

the / automatically changed \ in windows. if want create whole path @ 1 time have utilize mkdirs() method. more info: http://docs.oracle.com/javase/6/docs/api/java/io/file.html

in order set file permissions in windows have utilize setreadable(), setwritable() , setexecutable(). file class methods , set file owner's permissions. note mentioned methods added in java 1.6. in older versions have utilize (windows version):

runtime.getruntime().exec("attrib -r myfile");

java nio java-7 java-io

No comments:

Post a Comment