有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (6) 个答案

  1. # 1 楼答案

    File f = new File("C:\\TEST");
    try{
        if(f.mkdir()) { 
            System.out.println("Directory Created");
        } else {
            System.out.println("Directory is not created");
        }
    } catch(Exception e){
        e.printStackTrace();
    } 
    
  2. # 3 楼答案

    使用^{}

    new File('/path/to/folder').mkdir();
    
  3. # 5 楼答案

    调用^{},如下所示:

    new File(path).mkdir();
    
  4. # 6 楼答案

    使用Java 8:

    Files.createDirectories(Paths.get("/path/to/folder"));
    

    相同:

    new File("/path/to/folder").mkdirs();
    

    或者

    Files.createDirectory(Paths.get("/path/to/folder"));
    

    相同:

    new File("/path/to/folder").mkdir();