Читал что метод concat() более производительный чем сложение строк с помощью "+", решил значит попробовать, а оно не работает. В режиме тестирования переменная str принимает нужные значения из файла, но почему то эти значения не добавляются к переменной content. Я пробовал задавать на 52 строке кода разные значения для content, и все равно ничего не добавлялось.
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;
static {
//напишите тут ваш код
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
firstFileName = reader.readLine();
secondFileName = reader.readLine();
reader.close();
} catch (Exception 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();
System.out.println(f.getFileContent());
}
public interface ReadFileInterface {
void setFileName(String fullFileName);
String getFileContent();
void join() throws InterruptedException;
void start();
}
//напишите тут ваш код
public static class ReadFileThread extends Thread implements ReadFileInterface {
private String content ="";
private String fileName;
@Override
public void setFileName(String fullFileName) {
this.fileName = fullFileName;
}
@Override
public String getFileContent() {
return content;
}
@Override
public void run() {
String str;
try {
BufferedReader localReader = new BufferedReader(new FileReader(fileName));
while ((str = localReader.readLine()) != null){
this.content.concat(str);
this.content.concat(" ");
}
localReader.close();
this.content.trim();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//C:\ZZZ\file1.txt
//C:\Users\offic\OneDrive\Desktop\file2.txt