# Configuration File

## Creating a configuration file

{% tabs %}
{% tab title="Yaml" %}
{% code title="Normal Example" overflow="wrap" %}

```java
Configuration config = new YamlConfiguration(new File("path/file.yml"));
config.load(); // If the file doesn't exist it will create it.
```

{% endcode %}

{% code title="Factory Example" overflow="wrap" %}

```java
PreparedConfigurationFactory factory = new PreparedConfigurationFactory(
        ConfigurationFactory.YAML,
        new File("src/test/resources/test.yml")
);
        
Configuration config = factory.create().load();
```

{% endcode %}
{% endtab %}

{% tab title="Toml" %}
{% code title="Normal Example" overflow="wrap" %}

```java
Configuration config = new TomlConfiguration(new File("path/file.toml"));
config.load(); // If the file doesn't exist it will create it.
```

{% endcode %}

{% code title="Factory Example" overflow="wrap" %}

```java
PreparedConfigurationFactory factory = new PreparedConfigurationFactory(
        ConfigurationFactory.TOML,
        new File("src/test/resources/test.yml")
);
        
Configuration config = factory.create().load();
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Read

{% tabs %}
{% tab title="Basic" %}

```yaml
key: "Value"
```

```java
String string = config.getString("key");
```

There are many methods for almost all types.
{% endtab %}

{% tab title="Default values" %}

```yaml
```

```java
String string config.getString("key", "Default value");
```

If the value doesn't exist or returns null, it will use the default value instead.
{% endtab %}

{% tab title="List | Number | String -> String" %}

```yaml
key: "Value"

or

key:
- "Element 1"
- "Element 2"
```

```java
//                                  (path, list joiner, default value)
String string = config.getAdaptedString("key", "\n", "Default Value");
```

{% endtab %}
{% endtabs %}

## Write

```java
config.set("key", "value");
```

## Save Changes

```java
config.save();
```
