Спасайте, как из метода printSomething(), передать текст в 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 IOException {
PrintStream printStream = System.out;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream stream = new PrintStream(outputStream);
System.setOut(stream);
System.setOut(printStream);
testString.printSomething();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileOutputStream fileOutputStream = new FileOutputStream(reader.readLine());
fileOutputStream.write(outputStream.toByteArray());
System.out.println(outputStream.toString());
reader.close();
fileOutputStream.close();
}
public static class TestString {
public void printSomething() {
System.out.println("it's a text for testing");
}
}
}