Guest User

Untitled

a guest
Oct 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import java.io.*;
  2. class akik
  3. {
  4. public static void main(String s[])
  5. {
  6. try
  7. {
  8. BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
  9. System.out.println("Enter the path of the Source directory");
  10. String n1=bfr.readLine();
  11. File sour = new File(n1);
  12. System.out.println("Enter the path of the modified directory");
  13. String n2=bfr.readLine();
  14. File mod = new File(n2);
  15. System.out.println("Enter the path of the saved directory");
  16. String n3=bfr.readLine();
  17. File save = new File(n3);
  18. (new File(n3+"/unique")).mkdir();
  19. File saveu = new File(n3+"/unique");
  20. String[] chils = sour.list();
  21. if (chils == null) {
  22. System.out.println("Invalid Directory");
  23. }
  24. String[] chilm =mod.list();
  25. if (chilm == null) {
  26. System.out.println("Invalid Directory");
  27. }
  28. for(int i=0;i<chilm.length;i++)
  29. {
  30. Boolean ff=false;
  31. for(int j=0;j<chils.length&&!ff;j++)
  32. {
  33.  
  34. if(chilm[i].equals(chils[j])&&((new File(n2,chilm[i])).isDirectory())&&(new File(n1,chils[j]).isDirectory()))
  35. {
  36.  
  37. check(n2+"/"+chilm[i],n1+"/"+chils[j],n3);
  38. ff=true;
  39.  
  40. }
  41. else if(chilm[i].equals(chils[j]))
  42. {
  43. ff=true;
  44. if(!compare(n2+"/"+chilm[i],n1+"/"+chils[j]))
  45. {
  46. System.out.println();
  47. copy(new File(n2+"/"+chilm[i]),new File(save,chilm[i]));
  48.  
  49.  
  50. }
  51.  
  52. }
  53. }
  54. if(!ff)
  55. {
  56. copy(new File(n2+"/"+chilm[i]),new File(saveu,chilm[i]));
  57. }
  58. }
  59.  
  60. }
  61. catch(Exception e)
  62. {
  63. System.out.println(e);
  64. }
  65. System.out.println("FILE COPY PROGRAM DONE");
  66. }
  67. static void check(String a,String b,String c)
  68. {
  69. try
  70. {
  71.  
  72. File f1=new File(a);
  73. File f2=new File(b);
  74. File save=new File(c);
  75. File saveu=new File(c+"/unique");
  76. String[] s1=f1.list();
  77. String[] s2=f2.list();
  78.  
  79. for(int i=0;i<s1.length;i++)
  80. {
  81.  
  82. Boolean ff=false;
  83. for(int j=0;j<s2.length&&!ff;j++)
  84. {
  85.  
  86. if(s1[i].equals(s2[j]))
  87. {
  88.  
  89. if((new File(a,s1[i]).isDirectory())&&(new File(b,s2[j]).isDirectory()))
  90. {
  91.  
  92. check(a+"/"+s1[i],b+"/"+s2[j],c);
  93. ff=true;
  94. }
  95. else if(!compare(a+"/"+s1[i],b+"/"+s2[j]))
  96. {
  97. copy(new File(f1,s1[i]),new File(c,s1[i]));
  98. ff=true;
  99. }
  100.  
  101. }
  102.  
  103. }
  104. if(!ff)
  105. {
  106. copy(new File(f1,s1[i]),new File(c+"/unique",s1[i]));
  107. }
  108. }
  109. }
  110. catch(Exception e)
  111. {
  112. System.out.println(e+"akik");
  113. }
  114.  
  115. }
  116. static Boolean compare(String filePath1,String filePath2){
  117. try{
  118. File f1 = new File(filePath1);
  119. File f2 = new File(filePath2);
  120. if(f1.length() == f2.length()){
  121. FileInputStream fis1 = new FileInputStream(f1);
  122. FileInputStream fis2 = new FileInputStream(f2);
  123.  
  124. while(true){
  125. int a = fis1.read();
  126. int b = fis2.read();
  127. if(a != b){
  128. return false;
  129. }
  130. if(a == -1){
  131. return true;
  132. }
  133. }
  134. }else{
  135. return false;
  136. }
  137.  
  138. }catch(Exception e){
  139. e.printStackTrace();
  140. }
  141. return false;
  142. }
  143. static void copy(File src, File dst) throws IOException {
  144. InputStream in = new FileInputStream(src);
  145. OutputStream out = new FileOutputStream(dst);
  146.  
  147. byte[] buf = new byte[1024];
  148. int len;
  149. while ((len = in.read(buf)) > 0) {
  150. out.write(buf, 0, len);
  151. }
  152. in.close();
  153. out.close();
  154. }
  155.  
  156. }
Add Comment
Please, Sign In to add comment