过虑文件拷贝文件的java代码

来源:互联网 发布:上海游族网络 编辑:程序博客网 时间:2024/05/16 07:10

/**
     * @param args
     */
    static String sourcrRoot = "F:\\book\\eclipse插件\\jbosstools\\sourcefile";
    static String targetRoot = "F:\\jbosstoolsv2\\project\\base_Final";

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        File target = new File(targetRoot);
        String targetLs[] = target.list();
        List fooderPathLs = new ArrayList();
        FileOperate fo = new FileOperate();
        try {
            fo.showAllFileFolder(target, "plugins", fooderPathLs);
        } catch (Exception e) {
            e.printStackTrace();
        }
        for (int i = 0; i < fooderPathLs.size(); i++) {
            // System.out.println(fooderPathLs.get(i));
            try {
                targetMathSorce((String) fooderPathLs.get(i));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static private String getSourcePath(String path) {
        File target = new File(path);
        File forderLs[] = target.listFiles();
        FileNameFilter ff = new FileNameFilter("src");
        File folderLs[] = target.listFiles(ff);
        if (folderLs != null && folderLs.length > 0) {
            return folderLs[0].getAbsolutePath();
        } else {
            ff = new FileNameFilter("org");
            folderLs = target.listFiles(ff);
            if (folderLs != null && folderLs.length > 0) {
                return folderLs[0].getAbsolutePath();
            }
        }
        return "-1";
    }

    static private void targetMathSorce(String targetpath) throws Exception {
        File target = new File(targetpath);
        File tartetLs[] = target.listFiles();
        FileOperate fo = new FileOperate();
        File sourcr = new File(sourcrRoot);
        for (int i = 0; i < tartetLs.length; i++) {
            List filePathList = new ArrayList();

            fo.showAllStartWithFileFolder(sourcr, tartetLs[i].getName() + ".source_", filePathList);
            if (filePathList.size() == 0) {
                System.out.println(tartetLs[i] + "匹配到0条");
            } else {
                String srcPath = getSourcePath((String) filePathList.get(0));
                if ("-1".equals(srcPath)) {
                    System.out.println(tartetLs[i].getName() + "匹配到" + filePathList.size() + "条 但没有 src or org "
                                + (String) filePathList.get(0));
                } else {
                    System.out.println(tartetLs[i].getName() + "匹配到" + filePathList.size() + "条" + srcPath);
                    File tem = new File((String) filePathList.get(0));
                    if (srcPath.endsWith("src"))
                        fo.copyFolder(srcPath, tartetLs[i].getAbsolutePath() + "\\src");
                    else {
                        fo.copyFolder(srcPath, tartetLs[i].getAbsolutePath() + "\\src" + "\\org");
                    }
                }

            }
        }
    }

0 0