且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何比较两个文本文件的内容并返回“相同内容”或“不同的内容”?

更新时间:2022-11-17 13:53:46

最简单的方法是将内容读入两个字符串,例如

The simplest way is to read the contents into two strings e.g.

  FileInputStream fin =  new FileInputStream(args[i]);
  BufferedReader myInput = new BufferedReader(new InputStreamReader(fin));
  StringBuilder sb = new StringBuilder();
  while ((thisLine = myInput.readLine()) != null) {  
             sb.append(thisLine);
  }

,执行 .equals()就这些而言。您是否需要更复杂的差分功能?

, and perform a .equals() on these. Do you require more complex differencing capabilities ?