ivana_andreevska

Permisii za files

Feb 25th, 2022
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.io.*;
  2. import java.io.File;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) throws IOException {
  6.         File file = new File(".");
  7.         File[]files=file.listFiles();
  8.  
  9.         func(file);
  10.     }
  11.     static void func(File file)
  12.     {
  13.         File[]files=file.listFiles();
  14.         for(File f : files)
  15.         {
  16.             getPermissions(f);
  17.             if(f.isDirectory())
  18.                 func(f);
  19.         }
  20.     }
  21.     static void getPermissions(File f)
  22.     {
  23.         String pom="";
  24.         if(f.canRead())
  25.         {
  26.             pom+="R";
  27.         }else pom+=" ";
  28.  
  29.         if(f.canWrite())
  30.         {
  31.             pom+="W";
  32.         }else pom+=" ";
  33.  
  34.         if(f.canExecute())
  35.         {
  36.             pom+="X";
  37.         }else pom+=" ";
  38.         System.out.println(f.getName()+" "+ pom);
  39.     }
  40.  
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment