`
q_wong
  • 浏览: 108470 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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
 
分享到:
评论
1 楼 LinApex 2016-08-20  
没用啊你的代码

相关推荐

Global site tag (gtag.js) - Google Analytics