Advertisement
EgzonIseini

[OS] Lab 01 - Problem 1

Mar 21st, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FilenameFilter;
  3. import java.util.Arrays;
  4.  
  5. public class HW01_1 {
  6.     public static void main(String [] args) {
  7.         if(args.length != 0) {
  8.  
  9.             File f = new File(args[0]);
  10.  
  11.             File [] files = null;
  12.  
  13.             if(f.isDirectory()) {
  14.                     files = f.listFiles(new DirFilter(".txt"));
  15.             }
  16.  
  17.             long length = 0;
  18.  
  19.             if(files != null) for(File file : files) length += file.length();
  20.  
  21.             System.out.println(length / files.length);
  22.         }
  23.     }
  24. }
  25.  
  26. class DirFilter implements FilenameFilter
  27. {
  28.     private String filter;
  29.  
  30.     DirFilter(String filter) {
  31.         this.filter = filter;
  32.     }
  33.  
  34.     @Override
  35.     public boolean accept(File dir, String name) {
  36.         String tmp = new File(name).getName();
  37.         return tmp.contains(filter);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement