I don't see why this condition is not passed:
- output exactly meets specs as far as I can tell
- no extra space at the end of the last line
Insights, anyone?
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();
} 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();
//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 fullFileName;
private String result = "";
@Override
public void setFileName(String fullFileName) {
this.fullFileName = fullFileName;
}
@Override
public String getFileContents() {
if (this.getState() == State.TERMINATED)
return result;
else
return "";
}
@Override
public void run() {
File myFile = new File(fullFileName);
StringBuilder builder = new StringBuilder();
try {
Scanner myReader = new Scanner(myFile);
while (myReader.hasNextLine()) {
builder.append(myReader.nextLine());
if (myReader.hasNextLine()) builder.append(" ");
}
myReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
result = builder.toString();
}
}
}