Валидатор ругается и говорит: "Убедись что метод getFileContent возвращает пустую строку, если метод run не запускался."
я инициализировал изначально String content=null, сейчас, как думаю, проверил работу run() через try...catch, но всё не то.
с файлами, на компе работает как надо:
"E:/example2.txt //путь к файлам
E:/example.txt
String1 String2 String3 String4 // само содержимое файлов
line1 line2 line3 line4 "
А валидатор хочет не понятной для меня вещи. Подскажите как мне сделать, куда копать?
package com.javarush.task.task16.task1630;
import java.io.*;
/*
Последовательный вывод файлов
*/
// E:/example.txt
// E:/example2.txt
public class Solution {
public static String firstFileName;
public static String secondFileName;
static {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
firstFileName = reader.readLine();
secondFileName = reader.readLine();
//System.out.println("FirstFileName is " + firstFileName);
//System.out.println("SecondFileName is " + secondFileName);
} catch (IOException exception){
exception.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();
System.out.println(f.getFileContent());
}
public static class ReadFileThread extends Thread implements ReadFileInterface{
String content;
String fullFileName;
@Override
public void setFileName(String fullFileName) {
try {
this.fullFileName = fullFileName;
Thread.currentThread().join(1000);
// this.fullFileName = secondFileName;
}catch (InterruptedException exception){
exception.printStackTrace();
}
}
@Override
public String getFileContent() {
try {
run();
return content;
} catch (Exception e){
e.printStackTrace();
return null;
}
}
@Override
public void run() {
content = "";
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(fullFileName)));
} catch (FileNotFoundException exception){
exception.printStackTrace();
}
try {
if (reader!=null){
while (reader.ready()){
content = content + reader.readLine() + " ";
}
reader.close();
}
}catch (IOException exception){
exception.printStackTrace();
}
}
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContent();
void join() throws InterruptedException;
void start();
}
//add your code here - добавьте код тут
}