首页 > 编程语言 > 详细

拷贝JAR包

时间:2015-02-24 18:37:49      阅读:381      评论:0      收藏:0      [点我收藏+]
package com.cici;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;

public class TestCopy {
    private static List<File> files = new ArrayList();

      public static void main(String[] args)
        throws Exception
      {
        TestCopy tCP = new TestCopy();
        copyJars("D:\\path1", "D:\\path2");
      }
     public static String getFilesuffix(String strs)
      {
        String ss[] =  strs.split("\\.") ;
        return ss[1];
      }
      public static void copyJars(String sourceDir, String destDir)
        throws Exception
      {
        addJarsIntoList(sourceDir);

        File file = new File(destDir);
        if (file.isDirectory())
        {
          for (File f : files) {
            FileInputStream inputStream = new FileInputStream(f);
            FileUtils.copyFile(f, new File(file.getPath() + "\\" + f.getName()));
          }
        }
      }
      public static void addJarsIntoList(String path1)
      {
        File dir = new File(path1);
        if (dir.isDirectory())
        {
          File[] subFiles = dir.listFiles();
          for (File file : subFiles)
              //if it is file then we need to added into file list
            if (file.isFile())
              if (getFilesuffix(file.getName()).equals("jar"))
                files.add(file);
          //if it is not file it is just directory then we need to analize it then  it into directory
            else
              addJarsIntoList(file.getAbsolutePath());
        }
      }
}

 

拷贝JAR包

原文:http://www.cnblogs.com/cici-new/p/4298854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!