title: How to save a file from jersey response?
body: <p>I am trying to download a SWF file using Jersey from a web resource.</p>
  
  <p>I have written the following code, but am unable to save the file properly :</p>
  
  <pre><code>Response response = webResource.request(MediaType.APPLICATION_OCTET_STREAM)
    .cookie(cookie)
    .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
  
  String binarySWF = response.readEntity(String.class);                                     
  byte[] SWFByteArray = binarySWF.getBytes();       
  
  FileOutputStream fos = new FileOutputStream(new File("myfile.swf"));
  fos.write(SWFByteArray);
  fos.flush();
  fos.close();
  </code></pre>
  
  <p>It is save to assume that the response does return a SWF file, as <code>response.getMediaType</code> returns <code>application/x-shockwave-flash</code>.</p>
  
  <p>However when I try to open the SWF, nothing happen (also no error) which suggest that my file was not created from response.</p>