- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create directories recursively in Java
The method java.io.File.mkdirs() is used to create the specified directories, including the necessary parent directories. This method requires no parameters and it returns true on the success of the directories creation or false otherwise.
A program that demonstrates this is given as follows −
Example
import java.io.File; public class Demo { public static void main(String[] args) { String recursiveDirectories = "D:\a\b\c\d"; File file = new File(recursiveDirectories); boolean flag = file.mkdirs(); System.out.println("The directories are created recursively? " + flag); } }
The output of the above program is as follows −
Output
The directories are created recursively? true
Now let us understand the above program.
The method java.io.File.mkdirs() is used to create the specified directories recursively. The boolean value returned by the method is printed. A code snippet that demonstrates this is given as follows −
String recursiveDirectories = "D:\a\b\c\d"; File file = new File(recursiveDirectories); boolean flag = file.mkdirs(); System.out.println("The directories are created recursively? " + flag);
Advertisements