title: Compare two files line by line in scala
body: <p>I have 2 files,
  file1:</p>
  
  <pre><code>1
  2
  0
  2
  1
  2
  3
  2
  ...
  </code></pre>
  
  <p>and file2:</p>
  
  <pre><code>1
  2
  2
  2
  1
  1
  2
  1
  ...
  </code></pre>
  
  <p>how can i compare these two files line by line? i want to count lines which have same values. for example in two above files:</p>
  
  <pre><code>1=1
  2=2
  0!=2
  2=2
  ...
  </code></pre>
  
  <p>i've tried:</p>
  
  <pre><code> def main(args: Array[String]): Unit = {
      val lines = fromFile("data/file1.txt").getLines
      val lines2 = fromFile("data/file2.txt").getLines
      var l = 0
      var cnt = 0
      for (line &lt;- lines) {
        for (line2&lt;-lines2){
  
          if (line == line2){
            cnt += 1
          }
        }
  
        println(cnt)
  
      }
    }
  </code></pre>
  
  <p>but i doesn't show my favorite output.</p>