package core.utils.io;

import core.utils.logs.Logger;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class IOFileWriter
{
    //Перезаписывает...
    public void write(String path, String body)
    {
        try(BufferedWriter writer = new BufferedWriter(new FileWriter(path)))
        {
            writer.write(body);
            writer.newLine();
        }
        catch (IOException exception)
        {
            Logger.error("Exception occurred while writing file " + path + " " + exception.getMessage());
        }
    }


    //Дозаписывает...
    public void append(String path, String body)
    {
        try(BufferedWriter writer = new BufferedWriter(new FileWriter(path, true)))
        {
            writer.append(body);
            writer.newLine();
        }
        catch (IOException exception)
        {
            Logger.error("Exception occurred while writing file " + path + " " + exception.getMessage());
        }
    }
}