快速复制java对应的class文件,方便制作svn的patch。

最近手里好几个项目都在频繁的更新,我一直使用svn的patch制作补丁,但是因为class是不受svn管理的,每次更新的类都要手动的一个一个复制出来,少的时候没感觉怎么样,最近太多了,弄的我焦头烂额的,所以写了个小东西,自动根据已有的java文件,找对应的class复制过来。这样果然方便多了。

 

 


package com.radium.createpatch;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * 创建补丁
 * 
 * @author XieLei
 * @update 2011-11-9 下午2:15:45
 */
public class CreatePatch {
	static String path1 = "C:\\Users\\Radium-Work\\Desktop\\2011-11-9 84-140\\WebRoot\\WEB-INF\\classes";
	static String path2 = "D:\\WorkSpace\\neuedu-metallurgy\\trunk\\neuedu-metallurgy\\WebRoot\\WEB-INF\\classes";

	public static void main(String[] args) {
		File file1 = new File(path1);
		File file2 = new File(path2);

		if (file1.exists() && file2.exists()) {
			createPath(file1);
		}
		System.out.println("共复制:"+count);
	}

	static File tempFile1;
	static File tempFile2;
	static String tempStr;
	
	static int count = 0;

	public static void createPath(File file) {
		if (file.exists()) {
			File[] files = file.listFiles();
			for (File f : files) {
				if (f.isDirectory()) {
					createPath(f);
				} else {
					if (f.getName().endsWith(".java")) {
						count++;
						tempStr = path2 + f.getPath().substring(path1.length(), f.getPath().length());
						tempStr = tempStr .substring(0, tempStr.lastIndexOf(".")) + ".class";
						tempFile1 = new File(tempStr);
						tempFile2 = new File(f.getPath().substring(0, f.getPath().lastIndexOf("\\")+1)+f.getName().subSequence(0, f.getName().lastIndexOf(".")) +".class");
						if(tempFile1.exists()){
							try {
								copyFile(tempFile1,tempFile2);
								f.delete();
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
						System.out.println(f.getName());
					}
				}
			}
		}
	}

	/**
	 * 将F1复制到F2
	 * @param f1
	 * @param f2
	 * @return
	 * @throws Exception
	 * @author XieLei
	 * @update 2011-11-9 下午2:42:09
	 */
	public static void copyFile(File f1, File f2) throws Exception {
		int length = 2097152;
		FileInputStream in = new FileInputStream(f1);
		FileOutputStream out = new FileOutputStream(f2);
		byte[] buffer = new byte[length];
		
		int ins = 0;
		while (true && ins != -1) {
			ins = in.read(buffer);
			if(ins != -1)
				out.write(buffer, 0, ins);
		}
		
		in.close();
		out.flush();
		out.close();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值