In the section, you will learn how a directory or subdirectories are created. This program also explains the process of creating all non-existent ancestor directories automatically. We will use the File class to crate the directory.
File
The File class an abstract representation of file and directory pathnames. File
class is used to interact with the files system.
Here is the code for creating directory and all non-existing ancestor
directories:
import java.io.*;
|
Output of the program:
| C:\nisha>javac CreateDirectory.java C:\nisha>java CreateDirectory Directory: test created Directories: dir1/dir2/dir3 created C:\nisha> |
This program takes inputs to create a directory "test" and subdirectories "dir1\dir2\dir3". the mkdir( ) method is used to create a single directory while the mkdirs( ) method is used to create multiple subdirectories.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java Create Directory - Java Tutorial View All Comments
Post your Comment