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
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Checking Internet Connectivity using Java
- Copying file using FileStreams in Java
- File handling in Java using FileWriter and FileReader
- Delete a file using Java
- Moving a file from one directory to another using Java
- How to play an Audio file using Java
- Counting number of lines, words, characters and paragraphs in a text file using Java
- Creating a Cell at specific position in Excel file using Java
- Reading a CSV file in Java using OpenCSV
- Writing a CSV file in Java using OpenCSV
- Creating Sheets in Excel File in Java using Apache POI
- Convert byte array to File using Java
- Java program to store a Student Information in a File using AWT
- Java.io.File Class in Java
- Creating a file using FileOutputStream
- Redirecting System.out.println() output to a file in Java
- Myth about the file name and class name in Java
- Different ways of Reading a text file in Java
- Check if a File is hidden in Java
- File Permissions 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 email@example.com. 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.