I have to download a file and I'm using this code, which is basically an AsyncTask
that is meant to update a progress bar. But, since I don't know what's the file size I've been having to use the spinner progress bar. So, how can I get the file size before start downloading it so that I can use a normal progress bar?
Click the file or folder. Press Command + I on your keyboard. A window opens and shows the size of the file or folder.
If you visit the Chrome download Web page and click "Accept and Install," a dialog window opens that offers to save the file. It also shows the file's size. As of the date of publication, the size of the 23.0.
Every file on a computer uses a certain amount of resources when sent over the internet or stored. Keeping mind of your kilobytes (kB) and megabytes (MB) can prevent problems and produce a smoother online experience.
you can get a header called Content-Length
form the HTTP Response object that you get, this will give you the length of the file. you should note though, that some servers don't return that information, and the only way to know the actual size is to read everything from the response.
Example:
URL url = new URL("http://server.com/file.mp3"); URLConnection urlConnection = url.openConnection(); urlConnection.connect(); int file_size = urlConnection.getContentLength();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With