Q:

Scala Count Lines in a file VERY FAST

Count lines in a file (With BufferedInputStream) in Scala.
   object CountLinesScala {

  def main(args: Array[String]) {
    val c = countLines("C:/.../Motifs/mrr569.fasta")
    println(c)
  }

  def countLines(filename: String): Int = {
    val is = new BufferedInputStream(new FileInputStream(filename))
    try {
      val c = Array.ofDim[Byte](1024)
      var count = 0
      var readChars = 0
      var empty = true
      while ((readChars = is.read(c)) != -1) {
        empty = false
        for (i <- 0 until readChars if c(i) == '\n') {
          count=count +1
        }
      }
      if ((count == 0 && !empty)) 1 else count
    } finally {
      is.close()
    }
  }
}

its not working, Why ?
i click run but there is no reaction, and no Errors ! 

A:

You code is not working because the type of an assignation is Unit and you are comparing Unit to an Int (-1) which can never be equal, therefore your while loop never exits. 
More specifically, this expression has type Unit
(readChars = is.read(c)) 

if you want to fix your version of the program you could define an internal function doRead
  def doRead: Int = {
    readChars = is.read(c)
    readChars
  }

and use that in your while loop 
  while (doRead != -1) {
    empty = false
    for (i <- 0 until readChars if c(i) == '\n') {
      count=count +1
    }
  }

the final code for countLine would look like 
def countLines(filename: String): Int = {
    val is = new BufferedInputStream(new FileInputStream(filename))
    try {
      val c = Array.ofDim[Byte](1024)
      var count = 0
      var readChars = 0
      var empty = true
      def doRead: Int = {
        readChars = is.read(c)
        readChars
      }
      while (doRead!= -1) {
        empty = false
        for (i <- 0 until readChars if c(i) == '\n') {
          count=count +1
        }
      }
      if ((count == 0 && !empty)) 1 else count
    } finally {
      is.close()
    }
  }

However I advise you not to write Scala code like this. As was answered by brian, the most idiomatic way to write this would be to use the scala standard library and write 
scala.io.Source.fromFile("C:/.../Motifs/mrr569.fasta").getLines.size

Then your original program would become 
import scala.io.Source

object CountLinesScala {

  def main(args: Array[String]) {
    val c = Source.fromFile("C:/.../Motifs/mrr569.fasta").getLines().size
    println(c)
  }
}

