0

In android, how can I calculate the size of a data which I download or upload from internet?

Nguyen Minh Binh
  • 22,901
  • 30
  • 113
  • 160

2 Answers2

1

For uploading you might know the filesize. for example:

FileInputStream fileInputStream = new FileInputStream(sourceFile); 
int uploadSizeBytes = fileInputStream.available();

For download you may calculate it from loop while reading.

such as:

while(stream.read() != -1){
   bytesRead++ ;
}
Riad
  • 3,776
  • 5
  • 27
  • 38
1

this solution should solve your issue. If not you need to provide some source you are using

Community
  • 1
  • 1
Rafael T
  • 15,034
  • 14
  • 80
  • 142