Знаю что условия задачи другие - для валидатора код то я напишу. Это скорее для саморазвития. Сколько не дебажу - не могу уловить момент - почему не пишет в файл. На консоль вывод есть, а вот файл так остается пустой. Вроде как должно и в файл записать, что я упустил?
package com.javarush.task.task19.task1915;

/*
Дублируем текст
*/

import org.jetbrains.annotations.NotNull;

import java.io.*;


public class Solution {
    public static TestString testString = new TestString();

    public static void main(String[] args) throws IOException {
        BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
        String filePath = consoleReader.readLine();
        consoleReader.close();

        PrintStream myPrintStream = new MyPrintStream(System.out,new FileWriter(filePath));
        System.setOut(myPrintStream);

        testString.printSomething();
    }

    static class MyPrintStream extends PrintStream{

        private FileWriter fileWriter;
        private static final PrintStream standardOutput = System.out;

        public MyPrintStream(OutputStream out, FileWriter fileWriter){
            this(out);
            this.fileWriter = fileWriter;
        }


        public MyPrintStream(OutputStream out) {
            super(out);
        }

        @Override
        public void println(String x) {
            try {
                writeDuplicate(x);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void writeDuplicate(String str) throws IOException {
            super.println(str);
            fileWriter.write(str);
        }
    }

    public static class TestString {
        public void printSomething() {
            System.out.println("it's a text for testing");
        }
    }
}