I am trying to write code to monitor percentage progress of file transfers by dividing a running total by the total number of bytes in the file.
For some reason, when I divide the total by the total file bytes, I continuously get zero as a result.
total = long
percent = long
fileBytes = long
int bytesRead; while((bytesRead = in.read(bytes))>0) { total+=bytesRead; percent = (long) ((total/fileBytes)*100); System.out.println(Double.toString(percent)); buffout.write(bytes,0,bytesRead); } buffout.close();
I can't figure out why this is happening. Is the large number of file bytes outside of Java's range for longs?