никак не могу решить уже третий час(
package com.javarush.task.task18.task1825;
import java.io.*;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
/*
Собираем файл
*/
public class Solution {
public static void main(String[] args) throws IOException {
Textcompare com = new Textcompare();
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
Set<String> set = new TreeSet<>(com);
String text;
while (!(text = buf.readLine()).equals("end")){
set.add(text);
}
buf.close();
String directory = set.iterator().next();
String[] dyr = directory.split("\\.");
String trudir = "";
for (int i = 0; i < dyr.length - 1; i++) {
trudir += dyr[i];
}
FileOutputStream fos = new FileOutputStream(trudir);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(trudir));
for (String elem: set) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(elem));
while (bis.available() > 0) {
bos.write(bis.read());
}
fos.close();
}
}
}
class Textcompare implements Comparator<String> {
public int compare(String str1, String str2) {
String[] mas1 = str1.split("\\.");
String[] mas2 = str2.split("\\.");
int i1 = Integer.parseInt(mas1[mas1.length - 1].substring(4));
int i2 = Integer.parseInt(mas2[mas2.length - 1].substring(4));
return i1 - i2;
}
}