title: How can I retrieve the size of a file during the downloading from an URL (using a http connection)?
body: <p>I'm working on a project which download a file by using a http connection. I display a horizontal progress bar with the progress bar status during the downloading.
  My function looks like this:</p>
  
  <pre><code>.......
  try {           
          InputStream myInput = urlconnect.getInputStream();
          BufferedInputStream buffinput = new BufferedInputStream(myInput);
  
          ByteArrayBuffer baf = new ByteArrayBuffer(capacity);
          int current = 0;
          while((current = buffinput.read()) != -1) {
              baf.append((byte) current);
          }
  File outputfile = new File(createRepertory(app, 0), Filename);
          FileOutputStream myOutPut = new FileOutputStream(outputfile);
          myOutPut.write(baf.toByteArray());
  ...
  }
  </code></pre>
  
  <p>I know in advance the size of my file so I need to retrieve the size during the downloading (<em>in my while block</em>). Thus I'll be able to determinate the status of the progress bar.</p>
  
  <pre><code>progressBarStatus = ((int) downloadFileHttp(url, app) * 100)/sizefile;
  </code></pre>
  
  <p><em>long downloadFileHttp(.., ..) is the name of my function.</em></p>
  
  <p>I already try to retrieve it by using outputfile.length but his value is "1" maybe it's the number of file that I'm trying to download.</p>
  
  <blockquote>
    <p>Is there any way to figure it out?</p>
  </blockquote>
  
  <p><em><strong>UPDATE 1</em></strong></p>
  
  <blockquote>
    <p>I haven't got any thread which allow me to figure this out.
    Currently I have got a horizontal progress bar whch displays only 0 and 100% whitout intermediate values. I
    think about another approach. If I know the rate of my wifi and the
    size of the file I can determinate the time of downloading.</p>
    
    <p>I know that I can retrieve the piece of information of my Wifi
    connection and the size of my file to download. </p>
    
    <p>Is anybody already have worked or have thread on it?</p>
  </blockquote>