Валидация выдает:
1 - "Метод main(String[] args) класса Solution должен выводить и в консоль и в файл строку выведенную методом printSomething() (используй FileOutputStream). Убедись, что ты в своем решении используешь FileOutputStream.",
2 - "Поток записи в файл (FileOutputStream) должен быть закрыт.".
Подскажите, пожалуйста, где зарыта @ (и FileOutputStream иже с ней).
package com.javarush.task.task19.task1915;
/*
Дублируем текст
*/
import java.io.*;
public class Solution {
public static TestString testString = new TestString();
public static void main(String[] args) throws InterruptedException, IOException {
String fileName;
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader);) {
fileName = bufferedReader.readLine();
}
PrintStream console = System.out;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
PrintStream customStream = new PrintStream(byteOut);
System.setOut(customStream);
testString.printSomething();
String outResult = byteOut.toString();
System.setOut(console);
Runnable outToConsole = new Runnable() {
@Override
public void run() {
System.out.println(outResult);
}
};
Runnable writeToFile = new Runnable() {
@Override
public void run() {
try (FileOutputStream fileOutputStream = new FileOutputStream(fileName);) {
fileOutputStream.write(outResult.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
Thread threadConsole = new Thread(outToConsole);
Thread threadFile = new Thread(writeToFile);
threadConsole.start();
threadFile.start();
threadConsole.join();
threadFile.join();
}
public static class TestString {
public void printSomething() {
System.out.println("it's a text for testing");
}
}
}