title: Java "invalid stream header" error
body: <p>I'm having issues sending a file from one person to another in my program, I get a "invalid stream header" error.  Here is the code for sending and receiving the file, respectively:</p>
  
  <pre><code>private void sendFile(Socket socket, File file) throws IOException
  {
      int bytesRead;
      byte[] buffer;
      FileInputStream input;
      OutputStream output;
      buffer = new byte[(int)file.length()];
      input = new FileInputStream(file);
      output = socket.getOutputStream();
      bytesRead = input.read(buffer);
  
      while(bytesRead &gt; 0)
      {
          output.write(buffer,0,bytesRead);
          bytesRead = input.read(buffer);
      }
  
      input.close();
      output.close();
  }
  
  
  
  private void receiveFile(Socket socket, File file) throws IOException
  {
      int bytesRead;
      byte[] buffer;
      InputStream input;
      FileOutputStream output;
      buffer = new byte[(int)file.length()];
      output = new FileOutputStream(file);
      input = socket.getInputStream();
      bytesRead = input.read(buffer);
  
      while(bytesRead &gt; 0)
      {
          output.write(buffer,0,bytesRead);
          bytesRead = input.read(buffer);
      }
  
      input.close();
      output.close();
  }
  </code></pre>
  
  <p>I've already read up on Stack and everything I've tried hasn't fixed it.  Does anyone have any ideas?  Thanks!</p>
  
  <p>Exact error is:</p>
  
  <pre><code>java.io.StreamCorruptedException: invalid stream header: 3C736372
      at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
      at java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:299)
      at Message.readMessageFrom(Message.java:32)
      at Server$Handler.run(Server.java:220)
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>