Search code examples
javafilereturnmkdirs

Can't create file. mkdirs() Always return false


I have that code, but I can't create file. configFile.getParentFile().mkdirs(); return false.

That works some time ago, I just export my project and that stop work without any reason.

    File configFile = new File(ProfessionalWarns.getPluginDataFolder(),
            "config.yml");
    if (!configFile.exists()) {
        configFile.getParentFile().mkdirs();
        forceConfigUpdate = true;
    }

All class (that code for bukkit plugin): http://pastebin.com/hTPetAxu


Solution

  • mkdir creates a directory not a file. As you are getting the parent of a file, then calling mkdir on it, and it already exists, it is failing to create. Because the parent already exists.

    EDIT:

    You probably want to do:

    File configFile = new File(ProfessionalWarns.getPluginDataFolder(),
        "config.yml");
    if (!configFile.exists()) {
        boolean fileWasCreated = configFile.createNewFile();
        forceConfigUpdate = true;
    }