为什么提示 “确保在 run 方法未启动时 getFileContents 方法返回空字符串”
package zh.codegym.task.task16.task1630;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static String firstFileName;
public static String secondFileName;
public static volatile BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//在此编写你的代码
static{
try{
firstFileName = reader.readLine();
secondFileName = reader.readLine();
}
catch (IOException e){
}
}
public static void main(String[] args) throws InterruptedException {
systemOutPrintln(firstFileName);
systemOutPrintln(secondFileName);
try {
reader.close();
}
catch (IOException e){
}
}
public static void systemOutPrintln(String fileName) throws InterruptedException {
ReadFileInterface f = new ReadFileThread();
f.setFileName(fileName);
f.start();
//在此编写你的代码
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 {
String result = null;
String filename = null;
public void run(){
try {
BufferedReader rt = new BufferedReader(new FileReader(filename));
String tempString = null;
while((tempString = rt.readLine())!=null) {
result += tempString + " ";
}
rt.close();
}
catch (Exception e){
}
}
public void setFileName(String fullFileName){
this.filename = fullFileName;
}
public String getFileContents(){
if (null == result)
return null;
else
return result;
}
}
}