Java调BeyondCompare

public class CompareDemo {

	// 可执行程序的路径
	private String comparePath;
	// 执行脚本文件所在的路径
	private String execJSPath;

	public CompareDemo(String comparePath, String execJSPath) {
		this.comparePath = comparePath;
		this.execJSPath = execJSPath;
	}

	// 比较两个文件
	public boolean compareFile(String compareFile1, String compareFile2,
			String path) {

		String[] args = new String[] { comparePath, "@" + execJSPath,
				compareFile1.replace(" ", ""), compareFile2.replace(" ", ""),
				path };

		run(args);
		return true;
	}

	/**
	 * 执行一个命令行的方法
	 * 
	 * @param array
	 * @return
	 */
	public final int run(String... array) {

		try {
			ProcessBuilder builder = new ProcessBuilder();

			ProcessBuilder newBuilder = builder.command(array);

			builder.redirectErrorStream(true);

			// 创建进程, 执行发布任务
			Process process = newBuilder.start();

			InputStream inSTest = process.getInputStream();
			InputStreamReader reader = new InputStreamReader(inSTest);
			BufferedReader bfReader = new BufferedReader(reader);

			String strLine = "";
			while ((strLine = bfReader.readLine()) != null) {
				System.out.println(strLine);
				// log.info(strLine + "\r\n");
			}

			bfReader.close();
			process.waitFor();
			process.destroy();

			return process.exitValue();

		} catch (Exception e) {

			e.printStackTrace();

		}
		return -10000;
	}
}

 

 

public class TestCompareDemo {
	@Test
	public void test() {
		String comparePath = "D:\\Program Files\\Beyond Compare 3\\BCompare.exe";
		String execJSPath = "D:\\temp\\TestBYCompare\\compare.txt";
		CompareDemo compareDemo = new CompareDemo(comparePath, execJSPath);
		compareDemo.compareFile("D:\\temp\\TestBYCompare\\old",
				"D:\\temp\\TestBYCompare\\new",
				"D:\\temp\\TestBYCompare\\test.html");
	}
}

 

file-report layout:side-by-side &
options:ignore-unimportant,display-context,line-numbers &
output-to:%3 output-options:html-color,wrap-word %1 %2
 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值