To get the size of file from server first you need to connect to the server using URL and HttpURLConnection Class. To get the size of file we use getContentLength() method. As the size of file can be too large we use BigInteger class.
Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).
Java get file size using File classJava File length() method returns the file size in bytes. The return value is unspecified if this file denotes a directory.
I'm attempting to get a bunch of pdf links from a web service and I want to give the user the file size of each link.
Is there a way to accomplish this task?
Thanks
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