CodeGym give me a hinch : On startup, the getFileContents method invoked an empty string if the method being run runs.
I am a little confused , i commented out the funcion start, and the output was empty, meaby i do not understand what they want for me :(
Thank you for your attention
package pl.codegym.task.task16.task1630;
import java.io.*;
public class Solution {
public static String firstFileName;
public static String secondFileName;
//tutaj wpisz swój kod
static
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
try
{
firstFileName = read.readLine();
secondFileName = read.readLine();
}catch (IOException e){
e.getMessage();
}
}
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();
//tutaj wpisz swój kod
f.join();
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{
public String FileName = "";
private String Finishreading = " ";
@Override
public void run() {
File file = new File(FileName);
try{
BufferedReader br = new BufferedReader(new FileReader(file));
while ((Finishreading = br.readLine()) != null) {
System.out.print(Finishreading + " ");
}
}catch (Exception e)
{
e.getMessage();
}
}
@Override
public void setFileName(String fullFileName) {
this.FileName = fullFileName;
}
@Override
public String getFileContents() {
return Finishreading;
}
}
}