Guest User

Untitled

a guest
Jan 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class DirMove
  4. {
  5.  
  6. public DirMove()
  7. {
  8. }
  9.  
  10. public static void copyDir(File quelle, File ziel)
  11. throws FileNotFoundException, IOException
  12. {
  13. File files[] = quelle.listFiles();
  14. ziel.mkdirs();
  15. File afile[];
  16. int j = (afile = files).length;
  17. for(int i = 0; i < j; i++)
  18. {
  19. File file = afile[i];
  20. if(file.isDirectory())
  21. copyDir(file, new File((new StringBuilder(String.valueOf(ziel.getAbsolutePath()))).append(File.separator).append(file.getName()).toString()));
  22. else
  23. copyFile(file, new File((new StringBuilder(String.valueOf(ziel.getAbsolutePath()))).append(File.separator).append(file.getName()).toString()));
  24. }
  25.  
  26. }
  27.  
  28. private static void copyFile(File file, File ziel)
  29. throws FileNotFoundException, IOException
  30. {
  31. in = new BufferedInputStream(new FileInputStream(file));
  32. out = new BufferedOutputStream(new FileOutputStream(ziel, true));
  33. for(int bytes = 0; (bytes = in.read()) != -1;)
  34. out.write(bytes);
  35.  
  36. in.close();
  37. out.close();
  38. }
  39.  
  40. public static boolean delDir(File path)
  41. {
  42. File files[] = path.listFiles();
  43. if(files != null)
  44. {
  45. File afile[];
  46. int j = (afile = files).length;
  47. for(int i = 0; i < j; i++)
  48. {
  49. File file = afile[i];
  50. if(file.isDirectory())
  51. delDir(file);
  52. else
  53. if(!file.delete())
  54. return false;
  55. }
  56.  
  57. }
  58. path.delete();
  59. return true;
  60. }
  61.  
  62. private static BufferedInputStream in = null;
  63. private static BufferedOutputStream out = null;
  64.  
  65. }
Add Comment
Please, Sign In to add comment