Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. package lesson5;
  2.  
  3.  
  4. import java.io.*;
  5.  
  6. public class CopyFiles {
  7. public static void copy(String src, String dst, String exp) {
  8. File srcDir = new File(src);
  9. String[] files = srcDir.list(new FilenameFilter() {
  10. @Override
  11. public boolean accept(File dir, String name) {
  12. return name.endsWith(exp);
  13. }
  14. });
  15.  
  16. for (int i = 0; i < files.length; i++) {
  17. try {
  18. File file = new File(dst+"\\"+files[i]);
  19. file.createNewFile();
  20. FileOutputStream os = new FileOutputStream(file);
  21. FileInputStream is = new FileInputStream(src +"\\" + files[i]);
  22. byte[] buffer = new byte[1024];
  23. int length;
  24. while ((length = is.read(buffer)) > 0) {
  25. os.write(buffer, 0, length);
  26. }
  27.  
  28. os.close();
  29. is.close();
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33.  
  34. }
  35.  
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement