Уже пробывал куча вариаций в файлах , всё выводит правильно , лишних пробелов в конце и между слов. Возможно я не до конца понял задание и всё что в одной строке должно выводиться слитно без пробелов - тогда ошибку понимаю. А если всё по условию правильно то тогда я не догоняю где подвох , помогите разобраться пожалуйста :)
package com.javarush.task.task16.task1630;
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static String firstFileName;
public static String secondFileName;
//add your code here - добавьте код тут
static {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
File file1 = new File(reader.readLine());
File file2 = new File(reader.readLine());
firstFileName = file1.getName();
secondFileName = file2.getName();
reader.close();
} catch (IOException e) {
}
}
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();
//add your code here - добавьте код тут
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 {
public String name = "";
public String content = "";
public void setFileName(String s) {
this.name = s;
}
public String getFileContent() {
return this.content;
}
public void run() {
StringBuilder stringBuilder = new StringBuilder();
ArrayList myList = new ArrayList<String>();
String s;
try {
BufferedReader reader = new BufferedReader(new FileReader(new File(this.name)));
while ((s = reader.readLine()) != null) {
myList.add(s);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
for(Object str : myList){
this.content = stringBuilder.append(str + " ").toString().trim();
}
}
//add your code here - добавьте код тут
}
}