package com.javarush.task.task22.task2211;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/*
Смена кодировки
*/

public class Solution {
    public static void main(String[] args) throws IOException {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(args[0]));
             BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(args[1]))) {
            List<String> list = new ArrayList<>();
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                list.add(line);
            }

            for (int i = 0; i < list.size(); i++) {
                String s1 = list.get(i);
                byte[] inputBytes = s1.getBytes();

                String buffer = new String(inputBytes, Charset.forName("Windows-1251"));

                byte[] outputBytes = buffer.getBytes("UTF-8");
                String resultString = new String(outputBytes);

                bufferedWriter.write(resultString);
                if (i != list.size() - 1) {
                    bufferedWriter.newLine();
                }
            }
        } catch (IOException ignored) {
        }
    }
}