1.15.2 help with config

Discussion in 'Spigot Plugin Development' started by catssss, Apr 18, 2020.

  1. You need to create a new file if the file does not exist.

    Java's File constructor returns always a file, but it does not create a new File unless you are using File#createNewFile
     
  2. Since you're only using a single configuration file, you could just follow this tutorial in the spigot wiki to achieve the same result in a lot easier way.
     
    • Informative Informative x 1
  3. 1. how do I check if it exists or not I saw something about it but don't completely remember
    2. I wanted to do it this way because I wanted to try and figure out how to do it this way so I could use multiple files in the future.
     
  4. 1. File#exists.
    Do something like this:
    Code (Java):
    if(!file.getParentFile().exists()) file.getParentFile().mkdirs();
    if(!file.exists()) file.createNewFile();
     
    #5 TimeoutHD, Apr 18, 2020
    Last edited: Apr 19, 2020
  5. They should probably create the plugin's data directory before creating the config file itself:
    Code (Java):
    file.getParentFile().mkdirs();
     
    • Agree Agree x 2
  6. Yes indeed. Code corrected