mkdir(): This method is available in the java.io.File class of Java.
Syntax:
boolean java.io.File.mkdir()
This method creates the directory named by this abstract pathname.
Parameters: NA
Returns: true if and only if the directory was created; false otherwise.
Throws:
SecurityException - If a security manager exists and its java.lang.SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be created
Approach 1: When the directory created
Java
import java.io.File;public class Filemkdir {public static void main(String[] args) {String pathname = "D:\\hello1.txt";File file = new File(pathname);System.out.println(file.mkdir());}}
Output:
true
Approach 2: When the directory does not created
Java
import java.io.File;public class Filemkdir {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);System.out.println(file.mkdir());}}
Output:
false
No comments:
Post a Comment