title: How can I read a file to an InputStream then write it into an OutputStream in Scala?
body: <p>I'm trying to use basic Java code in Scala to read from a file and write to an <strong>OutputStream</strong>, but when I use the usual <strong>while( != -1 )</strong> in Scala gives me a warning "comparing types of Unit and Int with != will always yield true". </p>
  
  <p>The code is as follows:</p>
  
  <pre><code>    val file = this.cache.get(imageFileEntry).getValue().asInstanceOf[File]
      response.setContentType( "image/%s".format( imageDescription.getFormat() ) )
  
      val input = new BufferedInputStream( new FileInputStream( file ) )
      val output = response.getOutputStream()
  
      var read : Int = -1
  
      while ( ( read = input.read ) != -1 ) {
          output.write( read )
      }
  
      input.close()
      output.flush()
  </code></pre>
  
  <p>How am I supposed to write from an input stream to an output stream in Scala?</p>
  
  <p>I'm mostly interested in a <strong>Scala-like</strong> solution.</p>