# 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();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smuddgge.gitbook.io/squishy-library/configuration/configuration-file.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
