title: java progressbar for multiple file downloads
body: <p>I have to make a little p2p programm for a project. Everything works fine. I have set it up that the client can download multiple files at once(download use threads). My issue is now how can I actually get the overall progress of the download. I tried like this but it doesnt work</p>
  
  <pre><code>try {
                  int bytesRead;
                  InputStream in = mySocket.getInputStream();
                  DataInputStream clientData = new DataInputStream(in);
                  OutputStream output = new FileOutputStream(("./download/" + filename));
                  byte[] buffer = new byte[1024];
                  int currentProgress = 0;
                  while (filesize &gt; 0 &amp;&amp; (bytesRead = clientData.read(buffer, 0, (int) Math.min(buffer.length, filesize))) != -1) {                       
                      output.write(buffer, 0, bytesRead);
                      filesize -= bytesRead;
                      currentProgress = (int) ((((double)filesize) / ((double)size)) * 100d);
                      currentProgress = ((100-currentProgress)/ViewClient.countFiles);
                      System.out.println(currentProgress);
                  }
                  output.close();
                  in.close();
                  System.out.println("File "+filename+" received from client.");
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
  </code></pre>
  
  <p>with this each value(0,1,2,3) will be printed like 100 times and then my progress bar goes sometime up to 2'000'000 depends on the files. How can I get the overall downloaded content?
  Thank you in advance</p>