更新時間:2022-05-12 10:46:35 來源:動力節(jié)點 瀏覽2055次
在Java下如何創(chuàng)建目錄?動力節(jié)點小編來告訴大家。在 Java 中,該mkdir()函數(shù)用于創(chuàng)建新目錄。此方法將抽象路徑名作為參數(shù),并在 JavaFile類中定義。
mkdir()如果目錄創(chuàng)建成功,則返回true ;否則,它返回false ?。
看看mkdir()下面的函數(shù)簽名:
下面的代碼片段說明了該mkdir()函數(shù)創(chuàng)建新目錄的用法:
import java.io.*;
class CreateDirectory {
public static void main(String args[])
{
// specify an abstract pathname in the File object
File f = new File("D:\\Educative");
// check if the directory can be created
// using the specified path name
if (f.mkdir() == true) {
System.out.println("Directory has been created successfully");
}
else {
System.out.println("Directory cannot be created");
}
}
}
上面的代碼可能無法在在線 IDE 中運行。要編譯代碼,請將上述代碼復制到離線 IDE 中并設(shè)置適當?shù)穆窂健H绻蠹覍Υ吮容^感興趣,想了解更多相關(guān)知識,不妨來關(guān)注一下動力節(jié)點的Java視頻,里面的課程內(nèi)容從入門到精通,細致全面,通俗易懂,很適合沒有基礎(chǔ)的小伙伴學習,希望對大家能夠有所幫助。
相關(guān)閱讀