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

Java Example – Recursively Creating a Directory

Java Example – Recursively Creating a Directory

Java Examples Java Examples

The following example demonstrates using the mkdirs() method of the File class to recursively create a directory:

Main.java File

import

java

.

io

.

File

;

public

class

Main

{

public

static

void

main

(

String

[

]

args

)

{

String

directories

=

"

D:

\

a

\

b

\

c

\

d

\

e

\

f

\

g

\

h

\

i

"

;

File

file

=

new

File

(

directories

)

;

boolean

result

=

file

.

mkdirs

(

)

;

System

.

out

.

println

(

"

Status =

"

result

)

;

}

}

The output of the above code is:


Status = true

Java Examples Java Examples