A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to create directory/folder in particular drive
Q:

Java program to create directory/folder in particular drive

0

File.mkdir()

This is a method of "File" class in Java and used to create a directory at specified path, it return true if directory creates or returns false if directory does not create.

Here, first of all we are creating an object name dir of "File" class by specifying the "directory name with the path (drive name)" and then we are using dir.mkdir() method to create directory (Heredir is an object of "File" class).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to create directory in Java

import java.io.*;

public class CreateDirectory {
  public static void main(String[] args) {
    //object of File class with file path and name
    File dir = new File("E:/IHelp");

    //method 'mkdir' to create directroy and result
    //is getting stored in 'isDirectoryCreated'
    //which will be either 'true' or 'false'
    boolean isDirectoryCreated = dir.mkdir();

    //displaying results
    if (isDirectoryCreated)
      System.out.println("Directory successfully created: " + dir);
    else
      System.out.println("Directory was not created successfully: " + dir);
  }
}

Output

Directory successfully created: E:\IHelp

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now