Прошу глянуть на код
моя логика такая
отрабатываем run
устанавливаем значение информация в файле в переменную info
А дальше почему то теряется
ведь по идеи в этом потоке значение info установлено в методе run
и оно должны быть изменено))?
package com.javarush.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;
//add your code here - добавьте код тут
static {
BufferedReader name = new BufferedReader(new InputStreamReader(System.in));
try {
firstFileName = name.readLine();
secondFileName = name.readLine();
} catch (IOException e) {
e.printStackTrace();
}
// firstFileName = "C:\\11\\3.txt";
// secondFileName = "C:\\11\\4.txt";
}
public static class ReadFileThread extends Thread implements ReadFileInterface{
private String name;
private String info="";
@Override
public void setFileName(String fullFileName) {
name=fullFileName;
}
@Override
public String getFileContent() throws IOException {
return info;
}
public void run(){
try {
BufferedReader reader = new BufferedReader(new FileReader(name));
// System.out.println(name);
String s = "";
while (reader.ready()) {
s = s + reader.readLine();
}
info = s.trim();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws InterruptedException, IOException {
systemOutPrintln(firstFileName);
systemOutPrintln(secondFileName);
}
public static void systemOutPrintln(String fileName) throws InterruptedException, IOException {
ReadFileInterface f = new ReadFileThread();
f.setFileName(fileName);
f.start();
//add your code here - добавьте код тут
System.out.println(f.getFileContent());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContent() throws IOException;
void join() throws InterruptedException;
void start();
}
//add your code here - добавьте код тут
}