Unable to create file

Discussion in 'Plugin Development' started by RcExtract, Jun 16, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    RcExtract

    When I tried to create a configuration file, it says unable to find directory. Please help.

    Code:
    File file = new File(plugin.getDataFolder(), "config.yml");
    file.createNewFile(); //The line with problem
    
    I surrounded it with try catch block in the real code. But the problem is: won't it create a directory while creating a file when the directiory doesn't exist?
     
  2. Offline

    MrGriefer_

    Try:
    PHP:
    File file = new File(plugin.getDataFolder(), "config.yml");
            if(!
    file.exists()){
                try {
                    
    file.createNewFile();
                } catch (
    IOException e) {
                    
    e.printStackTrace();
                }
            }
    Or maybe just put reloadConfig(); in your on enable.
     
  3. Offline

    RcExtract

    That's what I tried
     
  4. Offline

    FrostDevStudios

    You should use this to after you check if the directory exists
     
Thread Status:
Not open for further replies.

Share This Page