Hi.
Could you give me a hint on what is wrong with the code? The output seems to be correct but validation fails.
package com.codegym.task.task16.task1630;
import java.io.*;
import java.util.Scanner;
public class Solution {
public static String firstFileName;
public static String secondFileName;
//write your code here
static {
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
try {
firstFileName=reader.readLine();
secondFileName=reader.readLine();
reader.close();
}
catch (IOException e){}
}
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();
//write your code here
f.join();
System.out.println(f.getFileContents());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContents();
void join() throws InterruptedException;
void start();
}
//write your code here
public static class ReadFileThread extends Thread implements ReadFileInterface{
private String fileContent="";
private String fileName="C:\\JavaRushTasks\\CodeGymTasks\\CodeGymTasks\\2.JavaCore\\src\\com\\codegym\\task\\task16\\task1630\\";
private boolean isRunMethodLoaded=false;
@Override
public void run() {
this.isRunMethodLoaded=true;
File file=new File(this.fileName);
try {
Scanner sc=new Scanner(file);
while (sc.hasNextLine()){
String temp=sc.nextLine();
if (sc.hasNextLine()) {
this.fileContent=this.fileContent+temp+" ";
}
else this.fileContent=this.fileContent+temp;
}
sc.close();
} catch (IOException e) {
this.isRunMethodLoaded=false;
}
}
@Override
public void setFileName(String fullFileName) {
this.fileName=this.fileName+fullFileName;
}
@Override
public String getFileContents() {
if (this.isRunMethodLoaded) return "["+this.fileContent+"]";
else return "";
}
}
}