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. You cannot use integer datatype as it can generate an error in case the size of file is greater than 2Gb.
To know more about BigInteger class refer link: BigInteger class in Java
For HttpURLConnection refer link: Java.net.HttpURLConnection Class in Java
- Checking Internet Connectivity using Java
- Java.io.File Class in Java
- Java | Renaming a file
- Java Class File
- Delete a file using Java
- File Permissions in Java
- Java | Appending String to a File
- Check if a File is hidden in Java
- Writing a CSV file in Java using OpenCSV
- Reading a CSV file in Java using OpenCV
- Moving a file from one directory to another using Java
- Myth about the file name and class name in Java
- How to play an Audio file using Java
- How to run java class file which is in different directory?
- Copying file using FileStreams in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.