Пробовал несколько вариантов, в том числе с list = new ArrayList<>() (как у других), и не понимаю почему не проходит.
Валидатор дает подсказку "убедитесь, что метод
public String getFileContent() { return fileContent;} возвращает null, если run() не запустится."
Да, я убедился, файл читается, в консоль выводится.
Что надо угадать?)
package com.javarush.task.task16.task1630;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Solution {
public static String firstFileName;
public static String secondFileName;
//add your code here - добавьте код тут
static {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
firstFileName = reader.readLine();
secondFileName = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException {
systemOutPrintln(firstFileName);
systemOutPrintln(secondFileName);
}
public static void systemOutPrintln(String fileName) throws InterruptedException {
ReadFileInterface f = new ReadFileThread();
f.setFileName(fileName);
f.start();
f.join(); //add your code here - добавьте код тут
System.out.println(f.getFileContent());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContent();
void join() throws InterruptedException;
void start();
}
//add your code here - добавьте код тут
public static class ReadFileThread extends Thread implements ReadFileInterface {
private String fileName;
private String fileContent;
@Override
public void run() {
String temp, tempContent = "";
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)))){
while ((temp = reader.readLine()) != null) {
tempContent += (temp + " ");
}
fileContent = tempContent.substring(0, tempContent.length() - 1);
} catch (IOException e) { }
}
@Override
public void setFileName(String fullFileName) {
this.fileName = fullFileName;
}
@Override
public String getFileContent() {
return fileContent;
}
}
}