# Creating a Configuration File

## YAML

Creating a single configuration file

<pre class="language-java" data-title="Example" data-overflow="wrap"><code class="lang-java"><strong>// Create a new instance of the configuration.
</strong><strong>Configuration configuration = new YamlConfiguration(
</strong><strong>    new File("src/main/resources"), "test.yml"
</strong><strong>);
</strong><strong>
</strong><strong>// This file will be copied from the resources folder 
</strong><strong>// if the configuration doesn't exist.
</strong><strong>configuration.setDefaultPath("test_default.yml");
</strong><strong>
</strong><strong>// Load the configuration file into memory.
</strong>configuration.load();

// Set a new value.
configuration.set("test", "test");

// Save the memory to the configuration file.
configuration.save();
</code></pre>

Creating a configuration factory

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

```java
// Creating the configuration factory.
// The factory can be used to change the type of configuration file
// with one variable.
ConfigurationFactory factory = ConfigurationFactory.YAML;

// Used to create a configuration file.
Configuration configuration1 = factory.create(
    new File("src/main/resources"), "test1"
);

// Used to create a configuration file.
Configuration configuration2 = factory.create(
    new File("src/main/resources"), "test2"
);

configuration1.load();
configuration1.set("test", "test");
configuration1.save();

configuration2.load();
configuration2.set("test", "test");
configuration2.save();
```

{% endcode %}

## TOML

Creating a single configuration file

```java
// Create a new instance of the configuration.
Configuration configuration = new TomlConfiguration(
    new File("src/main/resources"), "test.toml"
);

// Load the configuration file into memory.
configuration.load();

// Set a new value.
configuration.set("test", "test");

// Save the memory to the configuration file.
configuration.save();
```

Creating a configuration factory

```java
// Creating the configuration factory.
// The factory can be used to change the type of configuration file
// with one variable.
ConfigurationFactory factory = ConfigurationFactory.TOML;

// Used to create a configuration file.
Configuration configuration1 = factory.create(
    new File("src/main/resources"), "test1"
);

// Used to create a configuration file.
Configuration configuration2 = factory.create(
    new File("src/main/resources"), "test2"
);

configuration1.load();
configuration1.set("test", "test");
configuration1.save();

configuration2.load();
configuration2.set("test", "test");
configuration2.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-configuration/creating-a-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.
