码迷,mamicode.com
首页 > 编程语言 > 详细

拷贝JAR包

时间:2015-02-24 18:39:28      阅读:193      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!