Advertisement
simov

javaIO_avgust

Jun 20th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. package javaIO_avgust;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7.  
  8. public class javaIO_avgust {
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.         String in = "in";
  12.         String out = "out";
  13.         smallFiles(in, out);
  14.     }
  15.  
  16.     public static void smallFiles(String in, String out) throws IOException {
  17.         File inDir = new File(in);
  18.         File outDir = new File(out);
  19.         rekurzija(inDir, outDir);
  20.     }
  21.  
  22.     public static void rekurzija(File in, File out) throws IOException {
  23.         File[] fajlovi = in.listFiles();
  24.         long size = 0;
  25.         StringBuilder sb = new StringBuilder();
  26.         BufferedWriter bw = null;
  27.  
  28.         for (File f : fajlovi) {
  29.             if (f.isFile()) {
  30.                 if (f.getName().endsWith(".txt")) {
  31.                     size = f.length() / 1024;
  32.                     if (size < 100) {
  33.                         try {
  34.                             bw = new BufferedWriter(new FileWriter(out + "/files.txt"));
  35.  
  36.                             if (f.canRead()) {
  37.                                 if (f.canWrite()) {
  38.                                     if (f.canExecute()) {
  39.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "RWX" + System.lineSeparator());
  40.                                     } else {
  41.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "RW-" + System.lineSeparator());
  42.                                     }
  43.                                 } else {
  44.                                     if (f.canExecute()) {
  45.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "R-X" + System.lineSeparator());
  46.                                     } else {
  47.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "R--" + System.lineSeparator());
  48.                                     }
  49.                                 }
  50.                             } else {
  51.                                 if (f.canWrite()) {
  52.                                     if (f.canExecute()) {
  53.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "-WX" + System.lineSeparator());
  54.                                     } else {
  55.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "-W-" + System.lineSeparator());
  56.                                     }
  57.                                 } else {
  58.                                     if (f.canExecute()) {
  59.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "--X" + System.lineSeparator());
  60.                                     } else {
  61.                                         sb.append(f.getName() + ", " + f.getAbsolutePath() + ", " + "---" + System.lineSeparator());
  62.                                     }
  63.                                 }
  64.                             }
  65.                             String line = sb.toString();
  66.                             bw.write(line);
  67.  
  68.                         } finally {
  69.                             if (bw != null)
  70.                                 bw.close();
  71.                         }
  72.                     }
  73.                 }
  74.             } else if (f.isDirectory()) {
  75.                 rekurzija(f, out);
  76.             }
  77.         }
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement