import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class Chapter09ErrorsAndFiles {
    public static void saveHistory(Path file, List<String> lines)
            throws IOException {
        Files.write(file, lines);
    }

    public static void main(String[] args) {
        List<String> history = List.of("USER: hi", "BOT: Hello!");

        try {
            Path file = Files.createTempFile("history-java-", ".txt");
            saveHistory(file, history);
            System.out.println("History saved to: " + file);
        } catch (IOException error) {
            System.out.println("Could not save history.");
            System.err.println(error.getMessage());
        }
    }
}
