title: Jar file gets corrupted when sent over socket in Scala
body: <p>I'm aware that Scala uses Java sockets, but I don't quite understand the answers from questions that people have had with the same problem but strictly in Java.</p>
  
  <p>Here is my code:</p>
  
  <p>I am trying to send a jar file through a socket, but when I try to open the jar file from the other side, the file seems to be corrupted. How can I fix this?</p>
  
  <p>Server:</p>
  
  <pre><code>object server extends App {
    import java.net._
    import java.io._
    import scala.io._
  
    import scala.io.Source
  
    val server = new ServerSocket(9999)
  
    //Master should ping the slave actor to request for jar file
    while (true) {
        val s = server.accept()
        val in = new BufferedSource(s.getInputStream()).getLines()
        val out = new PrintStream(s.getOutputStream())
  
        val filename = "mapReduce.jar"
        for (line &lt;- Source.fromFile(filename, "ISO-8859-1").getLines)       {
            out.println(line)
            // println(line)
        }
  
  
        out.flush()
        s.close()
    }
  }
  </code></pre>
  
  <p>Along with the Client:</p>
  
  <pre><code>object client extends App {
    import java.net._
    import java.io._
    import scala.io._
    import java.util.jar._
  
    val s = new Socket(InetAddress.getByName("localhost"), 9999)
    lazy val in = new BufferedSource(s.getInputStream()).getLines()
    val out = new PrintStream(s.getOutputStream())
  
    out.println("Give me the jar file!")
    out.flush()
  
    val file = new File("testmapReduce.jar")
    val bw = new BufferedWriter(new FileWriter(file))
    while(in.hasNext) {
        val buf = in.next()
        bw.write(buf)
        // println(buf)
    }
  
  
    s.close()
    bw.close()
  
  
    println("Done!")
    val jar = new JarFile(file) //this part fails
  }
  </code></pre>