java 目录创建目录_用Java创建目录

2023-02-17 00:00:00 java 创建 目录

java 目录创建目录

The task is to create a directory in java.

任务是在Java中创建目录。

Creating a directory

创建目录

To create a directory, firstly we have to create a file object by passing the path of the directory where we have to create the directory and directory name.

创建目录 ,首先我们必须通过传递必须创建目录和目录名称的目录路径来创建文件对象。

The mkdir() method is used to create the directory, it is called with the file object that has the path where we have to create the directory and directory name, and returns a Boolean value (true – if directory created successfully, false – if the directory is not created).

mkdir()方法用于创建目录 ,使用具有我们必须在其中创建目录和目录名称的路径的文件对象调用该方法,并返回一个布尔值(true –如果成功创建了目录,false –目录未创建)。

Syntax:

句法:

    //file object creation by passing the path 
    File file = new File("d://course");

    //creating directory named "course" in "d://" drive
    file.mkdir();

    Output:
    true

Java代码创建目录 (Java code to create a directory)

//Java code to create a directory  
import java.io.*;

public class Main {
   
    public static void main(String[] args) {
   
        //file object creation by passing the path 
        //where we have to create the directory
        File file = new File("d://course");

        //variable to store the result
        //assigning false as an initial value
        boolean result = false;

        //creating directory named "course" in "d://" drive
        result = file.mkdir();

        if (result == true) {
   
            System.out.println("Directory created successfully...");
        } else {
   
            System.out.println("Directory is not created...");
        }
    }
}

Output

输出量

Directory created successfully...


翻译自: https://www.includehelp.com/java-programs/create-a-directory-in-java.aspx

java 目录创建目录

    原文作者:cumtb2009
    原文地址: https://blog.csdn.net/cumtb2009/article/details/107764948
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章