In this section, you will learn how to get the size of specified folder.
In the given example, we are going to show you the size of specified folder and also the number of files and folders that are presented in the specified folder. We have create a method getFileSize() in order to obtain the size of folder. The totalFolder++ counts the total folders and totalFile++ counts the total files.
Here is the video tutorial of "How to get Folder Size in Java?":
folder.getName()-This method returns the folder name.
folder.listFiles()- This method returns an array of files presented in the specified folder.
filelist[i].length() - This method returns the length of files presented in the specified folder.
Following code will calculate the size of folder in bytes.
|long fileSizeByte=size.getFileSize(new File(folder))|
Here is the code of GetFolderSize.java
Output will be displayed as:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles