Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Example – Getting the Directory Size

Java Example – Getting the Directory Size

Java Examples Java Examples

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 Java Examples