title: No number of bytes received in java
body: <p>I would like to determine the number of bytes downloaded from the following working URL connection:
  I have following code to implement:</p>
  
  <pre><code>   .......
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     connection.connect();
     InputStream is = connection.getInputStream();   // throws an IOException
     DataInputStream dis = new DataInputStream(new BufferedInputStream(is));          
  
     FileOutputStream fos = new FileOutputStream("C:\\Picture.jpeg");
     int read =0;
     byte[] bytes = new byte[1024];
     while((read = dis.read(bytes)) != -1)
     {
          fos.write(bytes, 0, read);
     }
     System.out.println(read + " byte(s) copied");
  </code></pre>
  
  <p>The output from the last line is as follows:</p>
  
  <pre><code>   Opening connection to http://www.xyz.com//Picture.jpeg...
     Copying image resource (type: application/jpeg, modified on: 02/02/2010 4:19:21 AM)...
    -1 byte(s) copied
  </code></pre>
  
  <p>What is the error of my code. please help me </p>