private void pipe(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[5000]; int nread; int navailable; int total = 0; int percentage = 0; //Percent done... int oldpercent = 0; synchronized (in) { while((nread = in.read(buf, 0, buf.length)) >= 0) { //Transfer out.flush(); out.write(buf, 0, nread); out.flush(); total += nread; //How many bytes already sent? percentage = (int)( ( total * 100.0 ) / filesize ); if(oldpercent < percentage){ System.out.println("%: " + percentage); } oldpercent = percentage; } } buf = null; }