Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lesson5;
- import java.io.*;
- public class CopyFiles {
- public static void copy(String src, String dst, String exp) {
- File srcDir = new File(src);
- String[] files = srcDir.list(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(exp);
- }
- });
- for (int i = 0; i < files.length; i++) {
- try {
- File file = new File(dst+"\\"+files[i]);
- file.createNewFile();
- FileOutputStream os = new FileOutputStream(file);
- FileInputStream is = new FileInputStream(src +"\\" + files[i]);
- byte[] buffer = new byte[1024];
- int length;
- while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
- }
- os.close();
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement