title: Client-Server File Transfer in Java
body: <p>I'm looking for an efficient way to transfer files between client and server processes using TCP in Java. My server code looks something like this:</p>
  
  <pre><code>socket = serverSocket.accept();
  InputStream is = socket.getInputStream();
  OutputStream os = socket.getOutputStream();
  
  FileInputStream fis = new FileInputStream(new File(filename));
  </code></pre>
  
  <p>I'm just unsure of how to proceed. I know I want to read bytes from <code>fis</code> and then write them to <code>os</code>, but I'm unsure about the best way to read and write bytes using byte streams in Java. I'm only familiar with writing/reading text using Writers and Readers. Can anyone tell me the appropriate way to do this? What should I wrap <code>os</code> and <code>fis</code> in (if anything) and how do I keep reading bytes until the end of file without a <code>hasNext()</code> method (or equivalent)</p>