Проверил на своих файлах - все работает корректно
Рекомендации от ментора:
Убедись, что метод getFileContent возвращает только вычитанный контент, и не добавляет к нему ничего лишнего.
package com.javarush.task.task16.task1630;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class Solution {
public static String firstFileName;
public static String secondFileName;
static {
Scanner sc = new Scanner(System.in);
firstFileName = sc.nextLine();
secondFileName = sc.nextLine();
}
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();
System.out.println(f.getFileContent());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContent();
void join() throws InterruptedException;
void start();
}
public static class ReadFileThread extends Thread implements ReadFileInterface {
String fullFileName;
ArrayList<String> list = new ArrayList<>();
@Override
public void setFileName(String fullFileName) {
this.fullFileName = fullFileName;
}
@Override
public String getFileContent() {
String str ="";
for(String s: list){
str = str+s+" ";
}
return str;
}
@Override
public void run() {
File file = new File(fullFileName);
Scanner sc = null;
try {
sc = new Scanner(file);
while(true){
String s = null;
s = sc.nextLine();
if (s == null)break;
list.add(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}