This statement in your code System.out.println(attr.toString()); will not 
print the permissions. The toString() operation on PosixFilePermissions class 
requires a parameter. Here is the method 
signature:PosixFilePermissions.toString​(Set<PosixFilePermission> perms) 




 
    On Monday, July 6, 2020, 8:08:10 PM GMT+4:30, slipbits 
<slipb...@slipbits.com> wrote:  
 
   
I am trying to create files/directories and to assign attributes to them. I 
would like my software to play on multiple OS's and I am trying to find the 
Java way of identifying OS specific attributes. Two issues came up. In one, 
there is no discussion of Windows attributes. I have assumed that they are the 
same as Posix. In the second case, I found a method (fromString()) which looks 
like a useful thing to know but can't get either NB12 or OpenBeans to recognize 
it and I'm stumped. 
 
 
The test code is:
 
package test;
 
 import java.nio.file.attribute.PosixFilePermission.fromString;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 
 public class test {
    public static void main(String[] args) {
      Set<PosixFilePermission> attr = fromString("rwxrw----");
      System.out.println(attr.toString());
    }; //  void main(String[] args) 
 }; // class test
 
 
 
I have tried to fix this with:
 
import java.nio.file.attribute.PosixFilePermission.*; and
 
 Set<PosixFilePermission> attr = 
java.nio.file.attribute.PosixFilePermission.fromString("rwxrw----");
 
 
without success. The puzzler is that the Java tutorial 
(https://docs.oracle.com/javase/tutorial/essential/io/fileAttr.html#dos) and 
the Java 1.8 documentation both seem to say that any of the above should work. 
 
 
Can anyone please help. Are the Windows attributes the same as Posix, and how 
can I use fromString()?
 
 

 
 

 
   

Reply via email to