title: java.io.EOFException when try to read from a socket
body: <p>i don't know why java.io.EOFException appear. i want to write a file after i get binary stream from server.</p>
  
  <p><strong>Here's my code</strong></p>
  
  <pre><code>inputStream = new DataInputStream(new BufferedInputStream(connection.getInputStream()));
  FileOutputStream fos = new FileOutputStream("D:/Apendo API resumable download.txt");
  
  byte b = inputStream.readByte();
  while(b != -1){
          fos.write(b);
          b = inputStream.readByte();                       
         }
  fos.close();
  </code></pre>
  
  <p><strong>Stack trace</strong></p>
  
  <pre><code>java.io.EOFException
  at java.io.DataInputStream.readByte(DataInputStream.java:267)
  at HttpRequestJSON.JSONRequest.sendRequest(JSONRequest.java:64)
  at HttpRequestJSON.Main.main(Main.java:56)
  </code></pre>