Custom data files not in the right spot

Discussion in 'Spigot Plugin Development' started by craterhater, May 29, 2017.

  1. Hey there,

    I got this code to generate custom configs:

    First:
    Code (Text):
    File dir = new File(getDataFolder()+"\\data");
            dir.mkdir();
           
            File dir2 = new File(getDataFolder()+"\\settings");
            dir2.mkdir();
    Then:
    Code (Text):
    File f = new File(main.getDataFolder()+"\\"+folder+"\\"+file+".yml");
            f.createNewFile();
    Yet they all generate in the plugin folder on the servers of some of my users. On my testing server this works fine though? Any ideas?
     
  2. electronicboy

    IRC Staff

  3. So like:
    Code (Text):
    new File(getDataFolder() + "\\FOLDER", "DATAFILE.YML");
    right?
     
  4. electronicboy

    IRC Staff

    No... You create a File instance for your actual folder, (and create the directories if needed), and then with that file instance for your folder, you create files using that. getDataFolder() + String call toString on getData... which returns the path to the folder which likely isn't what you want
     
  5. You should try something like this
    Code (Text):

    File file = new File(getDataFolder() + File.separator + "Database.yml");