java code -源代码合并

来源:互联网 发布:深圳市灵沃软件 编辑:程序博客网 时间:2024/06/05 12:00
package com.java.utils.filesmove;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.junit.Test;public class FilesMove {private static String filepath="D:/Users/quanchengyun970/Desktop/jboss-as-7.2.0.Final";private File  dest = new File("D:/jboss");@Testpublic void TestSimplified() throws IOException {//1.创建文件对象File base = new File(filepath);File[] docs = base.listFiles();for(int i=0;i<docs.length;i++) {String filename = docs[i].getName();if(filename.startsWith("spring-")) {File basedoc = new File(base,filename+"/src/main/java/org");if(basedoc.exists()) {System.out.println("<fileset dir=\""+basedoc.getPath()+"\">" +"<include name=\"**/*\"/></fileset>");}}}}@Testpublic void test() {//1.创建文件对象File base = new File(filepath);dest.mkdir();copyAll(base);}private void copyAll(File f) {if(f.isFile()&& f.getName().endsWith("java")) {copy(f);}if(!f.isDirectory()) {return;}File[] files = f.listFiles();for(int i=0;i<files.length;i++) {copyAll(files[i]);}}private void copy(File file) {String path = file.getPath();String pkgPath = path.substring(path.indexOf("java") + 5,path.lastIndexOf("\\"));try {String[] dir = pkgPath.split("\\\\");StringBuffer sb = new StringBuffer(dest.getPath());for (int i = 0; i < dir.length; i++) {sb.append("\\").append(dir[i]);File pa = new File(sb.toString());pa.mkdir();}sb.append("\\").append(file.getName());BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));byte[] b = new byte[in.available()];BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(sb.toString())));in.read(b);out.write(b);in.close();out.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (Exception e) {System.out.println(pkgPath);}}}

0 0
原创粉丝点击