evitanasevska

Untitled

Jun 20th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class JavaApplication {
  6.    
  7.     public static void deleteDir(File folder) {
  8.         File [] files = folder.listFiles();
  9.         for(File f : files) {
  10.             if(f.isDirectory()) {
  11.                 deleteDir(f);
  12.             }
  13.             else if(f.isFile()) {
  14.                 f.delete();
  15.             }
  16.         }
  17.         folder.delete();
  18.     }
  19.    
  20.     public static void zapisi(File file) throws IOException {
  21.         RandomAccessFile in = null;
  22.         RandomAccessFile out = null;
  23.         File to = new File("write-here.txt");
  24.         try {
  25.             in = new RandomAccessFile(file, "r");
  26.             out = new RandomAccessFile(to, "rw");
  27.            
  28.             out.seek(out.length());
  29.            
  30.             int c;
  31.             while((c=in.read()) != -1) {
  32.                 out.write(c);
  33.             }
  34.         }
  35.         catch (Exception e) {
  36.             // TODO: handle exception
  37.         }
  38.         finally {
  39.             if (in != null) in.close();
  40.             if (out != null) out.close();
  41.         }
  42.     }
  43.    
  44.     public static void funk(String from, String to) throws IOException {
  45.         File fromFile = new File(from);
  46.         File toFile = new File(to);
  47.        
  48.         if(fromFile.exists() && fromFile.isDirectory()) {
  49.             if(toFile.exists() && toFile.isDirectory()) {
  50.                 deleteDir(toFile);
  51.             }
  52.             else {
  53.                 toFile.mkdir();
  54.                 File[] fromFiles = fromFile.listFiles();
  55.                 for(File f : fromFiles) {
  56.                     if(f.getName().endsWith(".txt") && f.length() < 10){
  57.                         f.renameTo(new File(to, f.getName()));
  58.                     }
  59.                     else {
  60.                         zapisi(f);
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.         else {
  66.            
  67.         }
  68.        
  69.     }
  70.    
  71.     public static void main (String[]args) throws IOException {
  72.        
  73.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  74.         String [] pom = br.readLine().split(" ");
  75.         String from = pom[0];
  76.         String to = pom[1];
  77.    
  78.         funk(from,to);
  79.        
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment