# Property-файлы

Проперти файлы либо файлы свойств — предназначены для того, чтобы хранить в них какие-то статические данные, необходимые на проекте, например, логин и пароль к БД.

Создадим config.properties файл:

```
db.host = http://localhost:8888/mydb
db.login = root
db.password = dbroot
```

Как видите, данные представлены в виде {ключ} = {значение}, где

{ключ} — это уникальное имя, по которому можно получить доступ к значению, хранимому под этим ключом.

{значение} — это текст, либо число, которое вам необходимо для выполнения определённой логики в вашей программе.

Теперь давайте поробуем получить оттуда данные:

```
import java.io.*;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {
        FileInputStream fis;
        Properties property = new Properties();

        try {
            fis = new FileInputStream("src/main/resources/config.properties");
            property.load(fis);

            String host = property.getProperty("db.host");
            String login = property.getProperty("db.login");
            String password = property.getProperty("db.password");

            System.out.println("HOST: " + host
                            + ", LOGIN: " + login
                            + ", PASSWORD: " + password);

        } catch (IOException e) {
            System.err.println("ОШИБКА: Файл свойств отсутствует!");
        }
    }
}
```

Вопрос 1.

Для чего в указанном примере имена ключей имеют префикс "db."?

Вопрос 2.

Какие еще данные имело бы смысл хранить в property-файлах?


---

# 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://comaqa.gitbook.io/java-automation/rabota-s-failami/property-faily.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.
