Java Example – Getting the Directory Size
The following example demonstrates using the FileUtils.sizeofDirectory(File Name) method of the File class to get the size of a directory:
Main.java File
import
java
.
io
.
File
;
import
org
.
apache
.
commons
.
io
.
FileUtils
;
public
class
Main
{
public
static
void
main
(
String
[
]
args
)
{
long
size
=
FileUtils
.
sizeOfDirectory
(
new
File
(
"
C:/test
"
)
)
;
System
.
out
.
println
(
"
Size:
"
size
"
bytes
"
)
;
}
}
The output of the above code is:
Size: 2048 bytes
Java Examples