Advertisement
Guest User

Untitled

a guest
Sep 5th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. public static void copyDirectory(final File file, final File file2) {
  2. if (file.isDirectory()) {
  3. if (!file2.exists()) {
  4. file2.mkdir();
  5. }
  6. String[] list;
  7. for (int length = (list = file.list()).length, i = 0; i < length; ++i) {
  8. final String s = list[i];
  9. copyDirectory(new File(file, s), new File(file2, s));
  10. }
  11. }
  12. else {
  13. if (file.getName().equals("uid.dat") || file.getName().equals("session.dat")) {
  14. return;
  15. }
  16. try {
  17. copyFile(new FileInputStream(file), file2);
  18. }
  19. catch (FileNotFoundException ex) {
  20. ex.printStackTrace();
  21. Logger.warn("Failed to copy file from " + file.getName() + " to " + file2.getName());
  22. }
  23. }
  24. }
  25.  
  26. public static void copyFile(final InputStream inputStream, final File file) {
  27. try {
  28. final FileOutputStream fileOutputStream = new FileOutputStream(file);
  29. final byte[] array = new byte[710];
  30. int read;
  31. while ((read = inputStream.read(array)) > 0) {
  32. fileOutputStream.write(array, 0, read);
  33. }
  34. fileOutputStream.close();
  35. inputStream.close();
  36. }
  37. catch (Exception ex) {}
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement