The moose likes Beginning Java and the fly likes Size of File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Size of File" Watch "Size of File" New topic

Size of File

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear all,
How can I get the size of a folder ?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
I'm not sure if this is exactly what you're looking for, but I was able to come up with the size of all the files within a directory by using a recursive function, like this:

I'm not really sure if there is an easier way to do this or not, but it seems that simply calling the length method on a File object that represents a directory simply returns 0. Therefore, I had to look at each file individually and recurse through any subdirectories. The final result printed the size of all of the files contained within the directory C:\test in bytes.
I hope this helps you out.

SCJP Tipline, etc.
subject: Size of File
Similar Threads
WA #1.....word association
Is JDK same for all platforms(windows,unix,mac) or is it different for different operating systems.
Dateformat problem in iBatis
enlaring input box
BackgroundPanel.java cannot be placed in BorderLayout.NORTH