Hi all.
Can't find an error. The message is "Be sure that the getFileContents method returns all the file contents, not just a part of it. " I have tried many files and everytime the output is correct. Can someone give me a little hint? Thanks!
package com.codegym.task.task16.task1630;
import java.io.*;
public class Solution {
public static String firstFileName;
public static String secondFileName;
static {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
try {
firstFileName = buffer.readLine();
secondFileName = buffer.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
//write your code here
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();
//write your code here
System.out.println(f.getFileContents());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContents();
void join() throws InterruptedException;
void start();
}
public static class ReadFileThread extends Thread implements ReadFileInterface {
private static String fileName;
private String fileContent = "";
private boolean isDownloaded = false;
@Override
public void setFileName(String fullFileName) {
this.fileName = fullFileName;
}
@Override
public String getFileContents() {
fileContent = "";
if (!isDownloaded) {
return "";
}
try {
BufferedReader reader = new BufferedReader(new FileReader(fileName));
while (reader.ready()) {
if (!fileContent.isEmpty()) {
fileContent += " ";
}
fileContent += reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}
@Override
public void start() {
isDownloaded = true;
}
}
//write your code here
}