"Убедись, что метод getFileContent возвращает только вычитанный контент, и не добавляет к нему ничего лишнего". Не пойму, что этот метод лишнего добавляет.
package com.javarush.task.task16.task1630;
import java.io.*;
public class Solution {
public static volatile BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static String firstFileName;
public static String secondFileName;
static {
try {
firstFileName = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
try {
secondFileName = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
systemOutPrintln(firstFileName);
systemOutPrintln(secondFileName);
}
public static void systemOutPrintln(String fileName) throws InterruptedException, FileNotFoundException {
ReadFileInterface f = new ReadFileThread();
f.setFileName(fileName);
f.start();
f.join();
System.out.println(f.getFileContent());
}
public interface ReadFileInterface {
void setFileName(String fullFileName) throws FileNotFoundException;
String getFileContent() throws FileNotFoundException;
void join() throws InterruptedException;
void start();
}
public static class ReadFileThread extends Thread implements ReadFileInterface {
File file = null;
BufferedReader filereader = null;
String result = "";
public void setFileName (String fullName) throws FileNotFoundException {
file = new File(fullName);
filereader = new BufferedReader(new FileReader(file));
}
public String getFileContent () {
return result;
}
@Override
public void run() {
String substr = "";
boolean spaceflag = false;
while (true){
try {
if (!filereader.ready()) break;
substr = filereader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (!spaceflag){
result = result + substr;
spaceflag = true;
}
if (spaceflag)
result = result + " " + substr;
}
try {
filereader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}