I don't see what's the deal with this task and the requirements.
package com.codegym.task.task22.task2211;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
/*
Changing the encoding
*/
public class Solution {
public static void main(String[] args) throws IOException {
String firstFile = "B:\\code.txt";
String secondFile = "B:\\code1.txt";
BufferedReader br = new BufferedReader(new FileReader(firstFile));
BufferedWriter bw = new BufferedWriter(new FileWriter(secondFile));
Charset windows1251 = Charset.forName("Windows-1251");
Charset utf8 = StandardCharsets.UTF_8;
while (br.ready()) {
String line = br.readLine();
byte[] buffer = line.getBytes(windows1251);
line = new String(buffer, utf8);
bw.write(line);
}
br.close();
bw.close();
}
}