Save FileConfiguration

Discussion in 'Plugin Development' started by Robin Bi, Apr 3, 2015.

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

    Robin Bi

    I have an object of the type FileConfiguration. I write things to it, get things from it, and I'm happy with it. But I also have to save it. How can I do this without having its raw file of the type File?

    I've tried things like
    Code:
    public static boolean save(String path, String fileName) {
        File file = new File(path, fileName);
        try {
            YamlConfiguration.loadConfiguration(file).save(file.getAbsolutePath());
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    but it seems to do nothing, it doesn't even throw the exception.


    Thanks in advance :3
     
  2. Offline

    Robin Bi

    @FisheyLP the parameter "file" is of the variable type "File". I don't have this file though. I would have to get the path of the FileConfiguration object.
     
  3. and whats this?
     
  4. Offline

    Robin Bi

    @FisheyLP The method save(File file) is in the class of FileConfiguration. So far so good. But as I said, my code seems to not work, even though I'm exactly doing this.
     
  5. @Robin Bi
    Code:java
    1. .save(file.getAbsolutePath());

    is not the same as
    Code:java
    1. .save(file);
     
  6. Offline

    Robin Bi

    @FisheyLP

    Changed to
    Code:
    public static boolean save(String path, String fileName) {
        File file = new File(path, fileName);
        try {
            YamlConfiguration.loadConfiguration(file).save(file);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
    but it does not work either. It's neither saving data nor throwing an exception. The path is right, Syso(file.exists()) outputs true. I'd appreciate some more help, thanks for the time you already spent.
     
  7. Code:
    File fancyFile;
    FileConfiguration fancyConfig;
    
    public void setupFile() {
         fancyFile = new File(//MainClassInstance.getDataFolder(), "superconfig.yml");
         fancyConfig = YamlConfiguration.loadConfiguration(fancyFile);
    }
    
    public void savemySuperFile() {
         try { fancyConfig.save(fancyFile); } catch (IOExeception e) {}
    }
    
     
    DogeDebugger likes this.
  8. Offline

    nverdier

    @Robin Bi You can use EnviousAPI's Config class. Link in signature.
     
Thread Status:
Not open for further replies.

Share This Page