Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class JavaApplication {
- public static void deleteDir(File folder) {
- File [] files = folder.listFiles();
- for(File f : files) {
- if(f.isDirectory()) {
- deleteDir(f);
- }
- else if(f.isFile()) {
- f.delete();
- }
- }
- folder.delete();
- }
- public static void zapisi(File file) throws IOException {
- RandomAccessFile in = null;
- RandomAccessFile out = null;
- File to = new File("write-here.txt");
- try {
- in = new RandomAccessFile(file, "r");
- out = new RandomAccessFile(to, "rw");
- out.seek(out.length());
- int c;
- while((c=in.read()) != -1) {
- out.write(c);
- }
- }
- catch (Exception e) {
- // TODO: handle exception
- }
- finally {
- if (in != null) in.close();
- if (out != null) out.close();
- }
- }
- public static void funk(String from, String to) throws IOException {
- File fromFile = new File(from);
- File toFile = new File(to);
- if(fromFile.exists() && fromFile.isDirectory()) {
- if(toFile.exists() && toFile.isDirectory()) {
- deleteDir(toFile);
- }
- else {
- toFile.mkdir();
- File[] fromFiles = fromFile.listFiles();
- for(File f : fromFiles) {
- if(f.getName().endsWith(".txt") && f.length() < 10){
- f.renameTo(new File(to, f.getName()));
- }
- else {
- zapisi(f);
- }
- }
- }
- }
- else {
- }
- }
- public static void main (String[]args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String [] pom = br.readLine().split(" ");
- String from = pom[0];
- String to = pom[1];
- funk(from,to);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment