Advertisement
pattty847

Untitled

Feb 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. public static void copyFiles(String copyLoc, File files) throws FileNotFoundException {
  2. File copyFile = new File(copyLoc);
  3. // Create the directory for the new copy location
  4. if (copyFile.mkdir()) {
  5. try {
  6. int transferBytes;
  7. FileOutputStream outputStream = new FileOutputStream(copyFile);
  8. for (File f : files.listFiles()) {
  9. // list all files and if there is a directory in the first place open it with recursion
  10. System.out.println("listing files:" + Arrays.toString(files.listFiles()));
  11. if (f.isDirectory()) {
  12. System.out.println("directory recursion open: " + f.getAbsolutePath());
  13. copyFiles(f.getAbsolutePath(), f);
  14. }else if (f.isFile()) {
  15. FileInputStream inputStream = new FileInputStream(f);
  16. while ((transferBytes = inputStream.read()) != -1) {
  17. System.out.println(transferBytes);
  18. outputStream.write(transferBytes);
  19. }
  20. }
  21. }
  22.  
  23. } catch (IOException ex) {
  24. ex.getLocalizedMessage();
  25. }
  26. }
  27. }
  28. //--------------------------------------------------------------------------
  29. /*
  30.  
  31. //This is an old recursive directory method that printed the folder it was opening and the size
  32. if (file.isDirectory()) {
  33. for (File f : file.listFiles()) {
  34. long size = (f.length()/1000000);
  35. if (f.isDirectory()) {
  36. if(size >= 1) {
  37. System.out.println("Folder: " + f.getAbsolutePath() + "\nSize: " + size + " mb");
  38. }else{
  39. System.out.println("Folder: " + f.getAbsolutePath() + "\nSize: " + f.length() + " bytes");
  40. }
  41. printDir(f.getAbsoluteFile());
  42. }else if(f.isFile()) {
  43. if(size >= 1) {
  44. System.out.println("File: " + f.getName() + "\nSize: " + size + " mb");
  45. }else{
  46. System.out.println("File: " + f.getName() + "\nSize: " + f.length() + " bytes");
  47. }
  48. }else if(f.isHidden()) {
  49. if(size >= 1) {
  50. System.out.println("Hidden: " + f.getName() + "\nSize: " + size + " mb");
  51. }else{
  52. System.out.println("Hidden: " + f.getName() + "\nSize: " + f.length() + " bytes");
  53. }
  54. }else {
  55. System.out.println("Something is here but we cannot see it.");
  56. }
  57. }
  58. }
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement