title: Reading binary file from URLConnection
body: <p>I'm trying to read a binary file from a URLConnection. When I test it with a text file it seems to work fine but for binary files it doesn't. I'm using the following mime-type on the server when the file is send out:</p>
  
  <pre><code>application/octet-stream
  </code></pre>
  
  <p>But so far nothing seems to work. This is the code that I use to receive the file:</p>
  
  <pre><code>file = File.createTempFile( "tempfile", ".bin");
  file.deleteOnExit();
  
  URL url = new URL( "http://somedomain.com/image.gif" );
  
  URLConnection connection = url.openConnection();
  
  BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) );
  
  Writer writer = new OutputStreamWriter( new FileOutputStream( file ) );
  
  int c;
  
  while( ( c = input.read() ) != -1 ) {
  
     writer.write( (char)c );
  }
  
  writer.close();
  
  input.close();
  </code></pre>