JAVA-替换目录下所有同名文件

package com.company;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class Main {

    public static void main(String[] args) throws IOException {
        //替换目录
        String dir = "E://qwqe";
        getFile(dir);
    }


    private static void getFile(String path) throws IOException {
        //新文件地址
        String cpPath = "E://ietm.js";
        //文件名
        String cpName = "ietm.js";

        File file = new File(path);
        File[] array = file.listFiles();

        for (int i = 0; i < array.length; i++) {
            if (array[i].isFile()) {
                System.out.println("^^^^^" + array[i].getName());
                System.out.println("#####" + array[i]);
                System.out.println("*****" + array[i].getPath());
                if (array[i].getName().equals(cpName)) {

                    File file1 = new File(array[i].getPath());
                    if (file1.exists()) {
                        file1.delete();
                        System.out.println("删除成功");
                    }
                    File file2 = new File(cpPath);
                    File file3 = new File(array[i].getPath());
                    Files.copy(file2.toPath(), file3.toPath());
                }
            } else if (array[i].isDirectory()) {
                getFile(array[i].getPath());
            }
        }
    }
}